Struct StructOptions

Source
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: 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.

Implementations§

Source§

impl StructOptions

Source

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

Source§

fn clone(&self) -> StructOptions

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StructOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StructOptions

Source§

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

impl PartialEq for StructOptions

Source§

fn eq(&self, other: &StructOptions) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for StructOptions

Source§

impl StructuralPartialEq for StructOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.