Avoids using the big oxigraph::Error in model structures

pull/35/head
Tpt 5 years ago
parent fa2d6c412f
commit 42fafbe57f
  1. 9
      lib/src/model/literal.rs
  2. 5
      lib/src/model/named_node.rs
  3. 2
      lib/src/sparql/xml_results.rs

@ -2,8 +2,7 @@ use crate::model::named_node::NamedNode;
use crate::model::vocab::rdf; use crate::model::vocab::rdf;
use crate::model::vocab::xsd; use crate::model::vocab::xsd;
use crate::model::xsd::*; use crate::model::xsd::*;
use crate::Result; use oxilangtag::{LanguageTag, LanguageTagParseError};
use oxilangtag::LanguageTag;
use rio_api::model as rio; use rio_api::model as rio;
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt; use std::fmt;
@ -13,7 +12,7 @@ use std::option::Option;
/// ///
/// The default string formatter is returning a N-Triples, Turtle and SPARQL compatible representation: /// The default string formatter is returning a N-Triples, Turtle and SPARQL compatible representation:
/// ``` /// ```
/// # use oxigraph::Result; /// # use oxilangtag::LanguageTagParseError;
/// use oxigraph::model::Literal; /// use oxigraph::model::Literal;
/// use oxigraph::model::vocab::xsd; /// use oxigraph::model::vocab::xsd;
/// ///
@ -31,7 +30,7 @@ use std::option::Option;
/// "\"foo\"@en", /// "\"foo\"@en",
/// Literal::new_language_tagged_literal("foo", "en")?.to_string() /// Literal::new_language_tagged_literal("foo", "en")?.to_string()
/// ); /// );
/// # Result::Ok(()) /// # Result::<(), LanguageTagParseError>::Ok(())
/// ``` /// ```
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
pub struct Literal(LiteralContent); pub struct Literal(LiteralContent);
@ -64,7 +63,7 @@ impl Literal {
pub fn new_language_tagged_literal( pub fn new_language_tagged_literal(
value: impl Into<String>, value: impl Into<String>,
language: impl Into<String>, language: impl Into<String>,
) -> Result<Self> { ) -> Result<Self, LanguageTagParseError> {
let mut language = language.into(); let mut language = language.into();
language.make_ascii_lowercase(); language.make_ascii_lowercase();
Ok(Literal(LiteralContent::LanguageTaggedString { Ok(Literal(LiteralContent::LanguageTaggedString {

@ -1,5 +1,4 @@
use crate::Result; use oxiri::{Iri, IriParseError};
use oxiri::Iri;
use rio_api::model as rio; use rio_api::model as rio;
use std::fmt; use std::fmt;
@ -22,7 +21,7 @@ pub struct NamedNode {
impl NamedNode { impl NamedNode {
/// Builds and validate a RDF [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) /// Builds and validate a RDF [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri)
pub fn parse(iri: impl Into<String>) -> Result<Self> { pub fn parse(iri: impl Into<String>) -> Result<Self, IriParseError> {
Ok(Self::new_from_iri(Iri::parse(iri.into())?)) Ok(Self::new_from_iri(Iri::parse(iri.into())?))
} }

@ -434,7 +434,7 @@ fn build_literal(
match datatype { match datatype {
Some(datatype) => Ok(Literal::new_typed_literal(value, datatype)), Some(datatype) => Ok(Literal::new_typed_literal(value, datatype)),
None => match lang { None => match lang {
Some(lang) => Literal::new_language_tagged_literal(value, lang), Some(lang) => Ok(Literal::new_language_tagged_literal(value, lang)?),
None => Ok(Literal::new_simple_literal(value)), None => Ok(Literal::new_simple_literal(value)),
}, },
} }

Loading…
Cancel
Save