fix: clippy needless doctest main warning

This commit is contained in:
2025-07-15 19:16:34 +03:00
parent 9d365a9593
commit 89732ff8e2
3 changed files with 59 additions and 37 deletions

View File

@@ -34,39 +34,38 @@
//!
//! ```rust
//! use filecaster::FromFile;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Debug, Clone, PartialEq, FromFile, Serialize, Deserialize)]
//! #[derive(Debug, Clone, PartialEq, FromFile)]
//! struct AppConfig {
//! /// If the user does not specify a host, use `"127.0.0.1"`.
//! #[from_file(default = "127.0.0.1")]
//! host: String,
//!
//! /// Number of worker threads; defaults to `4`.
//! #[from_file(default = 4)]
//! workers: usize,
//! /// Port number; defaults to `8080`.
//! #[from_file(default = 8080)]
//! port: u16,
//!
//! /// If not set, use `false`. Requires `bool: Default`.
//! auto_reload: bool,
//! }
//!
//! fn main() {
//! fn example() {
//! // Simulate file content (e.g., from a JSON file)
//! let file_content = r#"{
//! "host": "localhost",
//! "workers": 8
//! }"#;
//! let file_content = r#"{ "host": "localhost", "port": 3000 }"#;
//!
//! // The `AppConfigFile` struct is automatically generated by `#[derive(FromFile)]`.
//! // It has all fields as `Option<T>`.
//! let partial_config: AppConfigFile = serde_json::from_str(file_content).unwrap();
//! let partial_config2 = partial_config.clone();
//!
//! // Use the generated `from_file` method to get the final config.
//! // Default values are applied for missing fields.
//! let config = AppConfig::from_file(Some(partial_config));
//! // or
//! let config: AppConfig = partial_config2.into();
//!
//! assert_eq!(config.host, "localhost");
//! assert_eq!(config.workers, 8);
//! assert_eq!(config.port, 3000);
//! assert_eq!(config.auto_reload, false); // `Default::default()` for bool is `false`
//!
//! println!("Final Config: {:#?}", config);
@@ -74,7 +73,7 @@
//! // Example with no file content (all defaults)
//! let default_config = AppConfig::from_file(None);
//! assert_eq!(default_config.host, "127.0.0.1");
//! assert_eq!(default_config.workers, 4);
//! assert_eq!(default_config.port, 8080);
//! assert_eq!(default_config.auto_reload, false);
//! }
//! ```