From 22423b59bd9b7c21e652f3b44bbc05e55848d635 Mon Sep 17 00:00:00 2001 From: Tpt Date: Fri, 8 Jun 2018 12:16:23 +0200 Subject: [PATCH] Adds some useful casts to Literal --- src/model/data.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/model/data.rs b/src/model/data.rs index 8eb7434f..a3d63a8f 100644 --- a/src/model/data.rs +++ b/src/model/data.rs @@ -93,6 +93,12 @@ pub enum Literal { lazy_static! { static ref XSD_BOOLEAN: NamedNode = NamedNode::from_str("http://www.w3.org/2001/XMLSchema#boolean").unwrap(); + static ref XSD_DOUBLE: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#double").unwrap(); + static ref XSD_FLOAT: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#float").unwrap(); + static ref XSD_INTEGER: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#integer").unwrap(); static ref XSD_STRING: NamedNode = NamedNode::from_str("http://www.w3.org/2001/XMLSchema#string").unwrap(); static ref RDF_LANG_STRING: NamedNode = @@ -193,6 +199,33 @@ impl From for Literal { } } +impl From for Literal { + fn from(value: usize) -> Self { + Literal::TypedLiteral { + value: value.to_string(), + datatype: XSD_INTEGER.clone(), + } + } +} + +impl From for Literal { + fn from(value: f32) -> Self { + Literal::TypedLiteral { + value: value.to_string(), + datatype: XSD_FLOAT.clone(), + } + } +} + +impl From for Literal { + fn from(value: f64) -> Self { + Literal::TypedLiteral { + value: value.to_string(), + datatype: XSD_DOUBLE.clone(), + } + } +} + impl FromStr for Literal { type Err = ();