[][src]Struct config_struct::StructOptions

pub struct StructOptions {
    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,
}

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: String

The 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: bool

Whether 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: SerdeSupport

Shorthand for generating the Serialize and Deserialize traits.

Defaults to No.

use_serde_derive_crate: bool

The 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: bool

Whether 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: DynamicLoading

Whether the load functions, if generated, are dynamic, and when.

Defaults to DebugOnly.

create_dirs: bool

Whether or not to create the parent directories of the output file, if they don't exist.

Defaults to true.

write_only_if_changed: bool

Whether 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: FloatSize

The type of floating point values in the config, where the format does not make it explicit.

Defaults to F64.

default_int_size: IntSize

The type of integer values in the config, where the format does not make it explicit.

Defaults to I64.

max_array_size: usize

The 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.

Methods

impl StructOptions[src]

pub fn serde_default() -> Self[src]

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

impl Clone for StructOptions[src]

impl Debug for StructOptions[src]

impl Default for StructOptions[src]

fn default() -> Self[src]

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());

impl Eq for StructOptions[src]

impl PartialEq<StructOptions> for StructOptions[src]

impl StructuralEq for StructOptions[src]

impl StructuralPartialEq for StructOptions[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.