From 1c6ecdd4ad54602da7961c30866c956d964825ce Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Wed, 30 Mar 2022 17:38:39 +0200 Subject: [PATCH] Fix doctests using derive See https://github.com/rust-lang/rust/issues/83583 --- src/lib.rs | 7 ++++++- src/toml.rs | 41 +++++++++++++++++++++-------------------- src/yaml.rs | 40 +++++++++++++++++++++------------------- 3 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 94d8be5..52f8e37 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,7 @@ //! #[config(default = 8080)] //! port: u16, //! } +//! # fn main() {} //! ``` //! //! As your application grows, oftentimes you want to split the configuration @@ -69,6 +70,7 @@ //! struct DbConf { //! // ... //! } +//! # fn main() {} //! ``` //! //! You can also attach some other attributes to fields. For example, with @@ -87,6 +89,7 @@ //! //! # #[derive(Config)] //! # struct Conf {} +//! # fn main() -> Result<(), Box> { //! // Load from a single file only. //! # #[cfg(feature = "toml")] //! let config = Conf::from_file("config.toml")?; @@ -98,7 +101,8 @@ //! .file("config.toml") //! .file("/etc/myapp/config.toml") //! .load()?; -//! # Ok::<(), Box>(()) +//! # Ok(()) +//! # } //! ``` //! //! But you can also assemble your configuration yourself. That's what @@ -220,6 +224,7 @@ pub use crate::file::{File, FileFormat}; /// #[config(default = "127.0.0.1")] /// bind: IpAddr, /// } +/// # fn main() {} /// ``` /// /// This derives `Config` for the two structs. diff --git a/src/toml.rs b/src/toml.rs index e01f095..a16ebfb 100644 --- a/src/toml.rs +++ b/src/toml.rs @@ -70,26 +70,27 @@ impl Default for FormatOptions { /// file: Option, /// } /// -/// -/// let toml = confique::toml::format::(FormatOptions::default()); -/// assert_eq!(toml, "\ -/// ## App configuration.\n\ -/// \n\ -/// ## The color of the app.\n\ -/// ##\n\ -/// ## Required! This value must be specified.\n\ -/// ##color =\n\ -/// \n\ -/// [log]\n\ -/// ## If set to `true`, the app will log to stdout.\n\ -/// ##\n\ -/// ## Default value: true\n\ -/// ##stdout = true\n\ -/// \n\ -/// ## If this is set, the app will write logs to the given file. Of course,\n\ -/// ## the app has to have write access to that file.\n\ -/// ##file =\n\ -/// "); +/// fn main() { +/// let toml = confique::toml::format::(FormatOptions::default()); +/// assert_eq!(toml, "\ +/// ## App configuration.\n\ +/// \n\ +/// ## The color of the app.\n\ +/// ##\n\ +/// ## Required! This value must be specified.\n\ +/// ##color =\n\ +/// \n\ +/// [log]\n\ +/// ## If set to `true`, the app will log to stdout.\n\ +/// ##\n\ +/// ## Default value: true\n\ +/// ##stdout = true\n\ +/// \n\ +/// ## If this is set, the app will write logs to the given file. Of course,\n\ +/// ## the app has to have write access to that file.\n\ +/// ##file =\n\ +/// "); +/// } /// ``` pub fn format(options: FormatOptions) -> String { let mut out = String::new(); diff --git a/src/yaml.rs b/src/yaml.rs index fde9af4..99cea98 100644 --- a/src/yaml.rs +++ b/src/yaml.rs @@ -72,25 +72,27 @@ impl Default for FormatOptions { /// } /// /// -/// let yaml = confique::yaml::format::(FormatOptions::default()); -/// assert_eq!(yaml, concat!( -/// "# App configuration.\n", -/// "\n", -/// "# The color of the app.\n", -/// "#\n", -/// "# Required! This value must be specified.\n", -/// "#color:\n", -/// "\n", -/// "log:\n", -/// " # If set to `true`, the app will log to stdout.\n", -/// " #\n", -/// " # Default value: true\n", -/// " #stdout: true\n", -/// "\n", -/// " # If this is set, the app will write logs to the given file. Of course,\n", -/// " # the app has to have write access to that file.\n", -/// " #file:\n", -/// )); +/// fn main() { +/// let yaml = confique::yaml::format::(FormatOptions::default()); +/// assert_eq!(yaml, concat!( +/// "# App configuration.\n", +/// "\n", +/// "# The color of the app.\n", +/// "#\n", +/// "# Required! This value must be specified.\n", +/// "#color:\n", +/// "\n", +/// "log:\n", +/// " # If set to `true`, the app will log to stdout.\n", +/// " #\n", +/// " # Default value: true\n", +/// " #stdout: true\n", +/// "\n", +/// " # If this is set, the app will write logs to the given file. Of course,\n", +/// " # the app has to have write access to that file.\n", +/// " #file:\n", +/// )); +/// } /// ``` pub fn format(options: FormatOptions) -> String { let mut out = String::new();