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

fn into(self) -> Value

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

fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer

impl From<ChronoDuration> for Duration

fn from(source: ChronoDuration) -> Self

impl Into<ChronoDuration> for Duration

fn into(self) -> ChronoDuration

impl Deserialize for Duration

fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error> where D: Deserializer

Derived Implementations

impl Eq for Duration

impl PartialEq for Duration

fn eq(&self, __arg_0: &Duration) -> bool

fn ne(&self, __arg_0: &Duration) -> bool

impl Ord for Duration

fn cmp(&self, __arg_0: &Duration) -> Ordering

impl PartialOrd for Duration

fn partial_cmp(&self, __arg_0: &Duration) -> Option<Ordering>

fn lt(&self, __arg_0: &Duration) -> bool

fn le(&self, __arg_0: &Duration) -> bool

fn gt(&self, __arg_0: &Duration) -> bool

fn ge(&self, __arg_0: &Duration) -> bool

impl Debug for Duration

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl Clone for Duration

fn clone(&self) -> Duration

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