pub trait TypedProperty {
// Required method
fn from_value(value: &PropertyValue) -> ConversionResult<Self>
where Self: Sized;
}Expand description
Represents a type which can be created from a PropertyValue
TypedProperty can be implemented for user-defined types to make it more convenient to parse
things. However, if you want to implement it for types that aren’t defined in your crate, you’ll
have to use a newtype.
Example:
use ccs2::{CommaSeparatedList, ToType};
let context = ccs2::Context::from_str_without_tracing("items = '1, 2, 3, 4'").unwrap();
let items = context.get_type::<CommaSeparatedList>("items")?;
assert_eq!(items.0, vec!["1", "2", "3", "4"]);Note: The combined error type of the “get and convert” chain is ContextError.
Required Methods§
fn from_value(value: &PropertyValue) -> ConversionResult<Self>where
Self: Sized,
Implementations on Foreign Types§
Source§impl TypedProperty for bool
impl TypedProperty for bool
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for f32
impl TypedProperty for f32
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for f64
impl TypedProperty for f64
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for i8
impl TypedProperty for i8
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for i16
impl TypedProperty for i16
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for i32
impl TypedProperty for i32
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for i64
impl TypedProperty for i64
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for u8
impl TypedProperty for u8
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for u16
impl TypedProperty for u16
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for u32
impl TypedProperty for u32
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for u64
impl TypedProperty for u64
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for DateTime<FixedOffset>
impl TypedProperty for DateTime<FixedOffset>
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for String
impl TypedProperty for String
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for Duration
Requires the extra_conversions feature, as it uses the humantime crate to do the parsing
impl TypedProperty for Duration
Requires the extra_conversions feature, as it uses the humantime crate to do the parsing
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for PathBuf
impl TypedProperty for PathBuf
fn from_value(prop: &PropertyValue) -> ConversionResult<Self>
Source§impl TypedProperty for SystemTime
Requires the extra_conversions feature, as it uses the chrono crate to do the parsing
impl TypedProperty for SystemTime
Requires the extra_conversions feature, as it uses the chrono crate to do the parsing
See chrono::DateTime::parse_from_rfc3339 for supported formatting