Struct foxbox_taxonomy::values::Duration
[−]
[src]
pub struct Duration(_);
A duration, also used to represent a time of day.
JSON
Represented by a (floating-point) number of seconds.
extern crate foxbox_taxonomy; extern crate chrono; use foxbox_taxonomy::values::*; use foxbox_taxonomy::parse::*; use foxbox_taxonomy::serialize::*; use chrono::Duration as ChronoDuration; let parsed = Duration::from_str("60.01").unwrap(); let duration : ChronoDuration = parsed.clone().into(); assert_eq!(duration.num_seconds(), 60); assert_eq!(duration.num_milliseconds(), 60010); let serialized: JSON = parsed.to_json(&mut MultiPart::new()); assert_eq!(serialized.as_f64().unwrap(), 60.01);
Trait Implementations
impl Parser<Duration> for Duration
fn description() -> String
fn parse(path: Path, source: &mut JSON) -> Result<Self, ParseError>
fn from_str(source: &str) -> Result<T, ParseError>
fn take(path: Path, source: &mut JSON, field_name: &str) -> Result<T, ParseError>
fn take_opt(path: Path, source: &mut JSON, field_name: &str) -> Option<Result<T, ParseError>>
fn take_vec_opt(path: Path, source: &mut JSON, field_name: &str) -> Option<Result<Vec<T>, ParseError>>
fn take_vec(path: Path, source: &mut JSON, field_name: &str) -> Result<Vec<T>, ParseError>
impl ToJSON for Duration
fn to_json(&self, parts: &mut BinaryParts) -> JSON
impl Into<Value> for Duration
impl Serialize for Duration
Serialization
Values are deserialized to a floating-point number of seconds.
extern crate serde; extern crate serde_json; extern crate foxbox_taxonomy; extern crate chrono; use foxbox_taxonomy::values::*; let duration = Duration::from(chrono::Duration::milliseconds(3141)); let duration_as_json = serde_json::to_string(&duration).unwrap(); assert_eq!(duration_as_json, "3.141"); let duration_back : Duration = serde_json::from_str(&duration_as_json).unwrap(); assert_eq!(duration, duration_back);