Module rdftk_core::literal[][src]

Expand description

The Literal type used in the object component of a statement. Literal values are always strings, although an optional data type can be provided to allow consumers to convert from string lexical forms.

Note that duration values can be provided using std::time::Duration, however the chrono crate’s chrono::Duration may also be used. This additional dependency also allows for correct formatting of duration lexical forms by converting all standard duration values to chrono durations which support the correct to_string form.

Example

use rdftk_core::{Literal, DataType};
let string_literal: Literal = "string value".into();
assert_eq!(string_literal.lexical_form(), "string value");
assert_eq!(string_literal.data_type().as_ref(), None);

let string_literal: Literal = Literal::with_language("string value", "en_US");
assert_eq!(string_literal.language().as_ref().unwrap(), "en_US");
assert_eq!(string_literal.data_type().as_ref(), None);

let typed_string_literal: Literal = Literal::string("string value");
assert_eq!(typed_string_literal.data_type().as_ref().unwrap(), &DataType::String);

let long_literal: Literal = Literal::with_type("212", DataType::Long);
assert_eq!(long_literal.data_type().as_ref().unwrap(), &DataType::Long);

let long_literal: Literal = 212u64.into();
assert_eq!(long_literal.lexical_form(), "212");

use std::time::Duration;

let duration_literal: Literal = Duration::from_secs(63542).into();
assert_eq!(duration_literal.lexical_form(), "PT63542S");
assert_eq!(duration_literal.data_type().as_ref().unwrap(), &DataType::Duration);

Structs

Literal

Enums

DataType