Enum settingsfile::Type
source · pub enum Type {
Text(String),
Switch(bool),
Int(i32),
Float(f32),
Complex(HashMap<String, Type>),
Array(Vec<Type>),
None,
}
Expand description
Generic type enum used to work with data inside a Settings
Only should be used when interacting with the result of a
get_value
.
use settingsfile::Type;
let settings = Settings::new(EmptyConfig{});
match settings.get_value("options") {
Some(Type::Text(option)) => { }, // a single option selected
Some(Type::Array(options)) => { }, // multiple options here,
_ => { }, // probably not valid because options in this case are strings
}
Variants
Text(String)
Switch(bool)
Int(i32)
Float(f32)
Complex(HashMap<String, Type>)
Array(Vec<Type>)
None
Implementations
sourceimpl Type
impl Type
pub fn is_text(&self) -> bool
pub fn is_switch(&self) -> bool
pub fn is_int(&self) -> bool
pub fn is_float(&self) -> bool
pub fn is_complex(&self) -> bool
pub fn is_array(&self) -> bool
pub fn is_none(&self) -> bool
pub fn to_text(&self) -> Option<String>
pub fn to_switch(&self) -> Option<bool>
pub fn to_int(&self) -> Option<i32>
pub fn to_float(&self) -> Option<f32>
pub fn to_complex(&self) -> Option<HashMap<String, Type>>
pub fn to_array(&self) -> Option<Vec<Type>>
pub fn to_string(&self) -> String
sourcepub fn flatten(&self, parent_key: Option<String>) -> Type
pub fn flatten(&self, parent_key: Option<String>) -> Type
Flattens the Type
.
If the type is anything but a Type::Complex
it just
returns a copy of the original Type
.
If the type is a Type::Complex
it returns a 1D Complex,
thus flattening it. This is usually used recursively to
flatten an entire Settings
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Type
impl<'de> Deserialize<'de> for Type
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<'a> SupportedType for &'a Type
impl<'a> SupportedType for &'a Type
impl StructuralPartialEq for Type
Auto Trait Implementations
impl RefUnwindSafe for Type
impl Send for Type
impl Sync for Type
impl Unpin for Type
impl UnwindSafe for Type
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more