pub struct StructOptions {Show 14 fields
pub format: Option<Format>,
pub struct_name: String,
pub const_name: Option<String>,
pub generate_const: bool,
pub derived_traits: Vec<String>,
pub serde_support: SerdeSupport,
pub use_serde_derive_crate: bool,
pub generate_load_fns: bool,
pub dynamic_loading: DynamicLoading,
pub create_dirs: bool,
pub write_only_if_changed: bool,
pub default_float_size: FloatSize,
pub default_int_size: IntSize,
pub max_array_size: usize,
}Expand description
Options for configuring the generation of a struct.
Fields§
§format: Option<Format>The format of the source data.
Defaults to None which will cause it to be inferred from the
file type.
struct_name: StringThe name of the resulting struct.
Defaults to "Config".
const_name: Option<String>The name of the resulting const, if generated.
Defaults to the value of struct_name in uppercase.
generate_const: boolWhether or not to generate a const instance of the struct.
Defaults to true.
derived_traits: Vec<String>A list of traits for the struct to derive.
Defaults to ["Debug", "Clone"]
(Note that the serde_support option below may add to this
list.)
serde_support: SerdeSupportShorthand for generating the Serialize and Deserialize traits.
Defaults to No.
use_serde_derive_crate: boolThe recommended way to derive Serialize and Deserialize
is via the serde crate’s
derive feature.
If you instead need to use the old method of including the
serde_derive crate, set this flag to true.
generate_load_fns: boolWhether or not to generate helper functions to load the struct at runtime.
Defaults to true.
Note: These load functions depend on the Deserialize
trait, as well as the relevant serde library for the config
format.
So for example, if you generate a struct from config.json
then you will have to enable serde_support for the
Deserialize trait, and you will also have to include the
serde_json library in your crate.
dynamic_loading: DynamicLoadingWhether the load functions, if generated, are dynamic, and when.
Defaults to DebugOnly.
create_dirs: boolWhether or not to create the parent directories of the output file, if they don’t exist.
Defaults to true.
write_only_if_changed: boolWhether to check if the destination file would be changed before writing output.
This is to avoid unnecessary writes from marking the
destination file as changed (which could, for example,
trigger a process which is watching for changes). This
option only works with the create_* functions.
Defaults to true.
default_float_size: FloatSizeThe type of floating point values in the config, where the format does not make it explicit.
Defaults to F64.
default_int_size: IntSizeThe type of integer values in the config, where the format does not make it explicit.
Defaults to I64.
max_array_size: usizeThe maximum array size, over which array values in the config will be represented as slices instead.
If set to 0, slices will always be used.
Defaults to 0.
Implementations§
Source§impl StructOptions
impl StructOptions
Sourcepub fn serde_default() -> Self
pub fn serde_default() -> Self
The default options plus serde support. This includes
Serialize/Deserialize traits, plus helpers functions
to load the config.
use config_struct::{StructOptions, SerdeSupport};
let options = StructOptions::serde_default();
assert_eq!(options, StructOptions {
serde_support: SerdeSupport::Yes,
generate_load_fns: true,
.. StructOptions::default()
});Trait Implementations§
Source§impl Clone for StructOptions
impl Clone for StructOptions
Source§fn clone(&self) -> StructOptions
fn clone(&self) -> StructOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StructOptions
impl Debug for StructOptions
Source§impl Default for StructOptions
impl Default for StructOptions
Source§fn default() -> Self
fn default() -> Self
use config_struct::*;
let default_options = StructOptions {
format: None,
struct_name: "Config".to_owned(),
const_name: None,
generate_const: true,
derived_traits: vec![
"Debug".to_owned(),
"Clone".to_owned(),
],
serde_support: SerdeSupport::No,
use_serde_derive_crate: false,
generate_load_fns: false,
dynamic_loading: DynamicLoading::DebugOnly,
create_dirs: true,
write_only_if_changed: true,
default_float_size: FloatSize::F64,
default_int_size: IntSize::I64,
max_array_size: 0,
};
assert_eq!(default_options, StructOptions::default());