From b41b90cd6bc70b57ec0c55608b98b3c48edb6bb0 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 9 Feb 2024 01:40:17 -0500 Subject: [PATCH] literal --- lib/oxrdf/src/literal.rs | 10 +++++++++- lib/oxsdatatypes/src/geopoint.rs | 7 +++++++ lib/oxsdatatypes/src/lib.rs | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/oxrdf/src/literal.rs b/lib/oxrdf/src/literal.rs index 0872fab5..16055063 100644 --- a/lib/oxrdf/src/literal.rs +++ b/lib/oxrdf/src/literal.rs @@ -1,5 +1,5 @@ use crate::named_node::NamedNode; -use crate::vocab::{rdf, xsd}; +use crate::vocab::{geosparql, rdf, xsd}; use crate::NamedNodeRef; use oxilangtag::{LanguageTag, LanguageTagParseError}; #[cfg(feature = "oxsdatatypes")] @@ -422,6 +422,14 @@ impl From for Literal { } } +#[cfg(feature = "oxsdatatypes")] +impl From for Literal { + #[inline] + fn from(value: GeoPoint) -> Self { + Self::new_typed_literal(value.to_string(), geosparql::WKT_LITERAL) + } +} + /// A borrowed RDF [literal](https://www.w3.org/TR/rdf11-concepts/#dfn-literal). /// /// The default string formatter is returning an N-Triples, Turtle, and SPARQL compatible representation: diff --git a/lib/oxsdatatypes/src/geopoint.rs b/lib/oxsdatatypes/src/geopoint.rs index ac02a1b7..83d05ed1 100644 --- a/lib/oxsdatatypes/src/geopoint.rs +++ b/lib/oxsdatatypes/src/geopoint.rs @@ -1,3 +1,5 @@ +use std::fmt; +use std::fmt::Formatter; use std::str::FromStr; use thiserror::Error; use wkt::types::Point; @@ -38,6 +40,11 @@ impl FromStr for GeoPoint { } } +impl fmt::Display for GeoPoint { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} #[cfg(test)] mod tests { #![allow(clippy::panic_in_result_fn)] diff --git a/lib/oxsdatatypes/src/lib.rs b/lib/oxsdatatypes/src/lib.rs index 690f8fa8..82005a0d 100644 --- a/lib/oxsdatatypes/src/lib.rs +++ b/lib/oxsdatatypes/src/lib.rs @@ -25,4 +25,5 @@ pub use self::duration::{ ParseDurationError, YearMonthDuration, }; pub use self::float::Float; +pub use self::geopoint::{GeoPoint, GeoPointError}; pub use self::integer::{Integer, TooLargeForIntegerError};