diff --git a/lib/oxrdf/src/named_node.rs b/lib/oxrdf/src/named_node.rs index 23a156d6..9b545bcc 100644 --- a/lib/oxrdf/src/named_node.rs +++ b/lib/oxrdf/src/named_node.rs @@ -216,3 +216,21 @@ impl PartialOrd> for NamedNode { self.as_ref().partial_cmp(other) } } + +impl From> for NamedNode { + #[inline] + fn from(iri: Iri) -> Self { + Self { + iri: iri.into_inner(), + } + } +} + +impl<'a> From> for NamedNodeRef<'a> { + #[inline] + fn from(iri: Iri<&'a str>) -> Self { + Self { + iri: iri.into_inner(), + } + } +} diff --git a/lib/oxrdfxml/src/parser.rs b/lib/oxrdfxml/src/parser.rs index 9f64da00..279d0301 100644 --- a/lib/oxrdfxml/src/parser.rs +++ b/lib/oxrdfxml/src/parser.rs @@ -1157,17 +1157,15 @@ impl RdfXmlReader { fn resolve(base_iri: &Option>, relative_iri: String) -> Result { if let Some(base_iri) = base_iri { - Ok(NamedNode::new_unchecked( - base_iri - .resolve(&relative_iri) - .map_err(|error| SyntaxError { - inner: SyntaxErrorKind::InvalidIri { - iri: relative_iri, - error, - }, - })? - .into_inner(), - )) + Ok(base_iri + .resolve(&relative_iri) + .map_err(|error| SyntaxError { + inner: SyntaxErrorKind::InvalidIri { + iri: relative_iri, + error, + }, + })? + .into()) } else { NamedNode::new(relative_iri.clone()).map_err(|error| SyntaxError { inner: SyntaxErrorKind::InvalidIri { diff --git a/lib/oxttl/src/line_formats.rs b/lib/oxttl/src/line_formats.rs index 6a253658..5990c889 100644 --- a/lib/oxttl/src/line_formats.rs +++ b/lib/oxttl/src/line_formats.rs @@ -59,7 +59,7 @@ impl RuleRecognizer for NQuadsRecognizer { NQuadsState::ExpectSubject => match token { N3Token::IriRef(s) => { self.subjects - .push(NamedNode::new_unchecked(s.into_inner()).into()); + .push(NamedNode::from(s).into()); self.stack.push(NQuadsState::ExpectPredicate); self } @@ -82,7 +82,7 @@ impl RuleRecognizer for NQuadsRecognizer { NQuadsState::ExpectPredicate => match token { N3Token::IriRef(p) => { self.predicates - .push(NamedNode::new_unchecked(p.into_inner())); + .push(p.into()); self.stack.push(NQuadsState::ExpectedObject); self } @@ -94,7 +94,7 @@ impl RuleRecognizer for NQuadsRecognizer { NQuadsState::ExpectedObject => match token { N3Token::IriRef(o) => { self.objects - .push(NamedNode::new_unchecked(o.into_inner()).into()); + .push(NamedNode::from(o).into()); self.stack .push(NQuadsState::ExpectPossibleGraphOrEndOfQuotedTriple); self @@ -151,7 +151,7 @@ impl RuleRecognizer for NQuadsRecognizer { self.objects.push( Literal::new_typed_literal( value, - NamedNode::new_unchecked(d.into_inner()), + d ) .into(), ); @@ -167,7 +167,7 @@ impl RuleRecognizer for NQuadsRecognizer { N3Token::IriRef(g) if self.with_graph_name => { self.emit_quad( results, - NamedNode::new_unchecked(g.into_inner()).into(), + NamedNode::from(g).into(), ); self.stack.push(NQuadsState::ExpectDot); self diff --git a/lib/oxttl/src/n3.rs b/lib/oxttl/src/n3.rs index 7167df09..d1847991 100644 --- a/lib/oxttl/src/n3.rs +++ b/lib/oxttl/src/n3.rs @@ -778,7 +778,7 @@ impl RuleRecognizer for N3Recognizer { N3State::PathItem => { match token { N3Token::IriRef(iri) => { - self.terms.push(NamedNode::new_unchecked(iri.into_inner()).into()); + self.terms.push(NamedNode::from(iri).into()); self } N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) { @@ -860,7 +860,7 @@ impl RuleRecognizer for N3Recognizer { } N3State::IriPropertyList => match token { N3Token::IriRef(id) => { - self.terms.push(NamedNode::new_unchecked(id.into_inner()).into()); + self.terms.push(NamedNode::from(id).into()); self.stack.push(N3State::PropertyListEnd); self.stack.push(N3State::PredicateObjectList); self @@ -940,7 +940,7 @@ impl RuleRecognizer for N3Recognizer { N3State::LiteralExpectDatatype { value } => { match token { N3Token::IriRef(datatype) => { - self.terms.push(Literal::new_typed_literal(value, NamedNode::new_unchecked(datatype.into_inner())).into()); + self.terms.push(Literal::new_typed_literal(value, datatype).into()); self }, N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) { diff --git a/lib/oxttl/src/terse.rs b/lib/oxttl/src/terse.rs index 151ee062..cedf089e 100644 --- a/lib/oxttl/src/terse.rs +++ b/lib/oxttl/src/terse.rs @@ -127,7 +127,7 @@ impl RuleRecognizer for TriGRecognizer { TriGState::TriplesOrGraph => match token { N3Token::IriRef(iri) => { self.stack.push(TriGState::WrappedGraphOrPredicateObjectList { - term: NamedNode::new_unchecked(iri.into_inner()).into() + term: NamedNode::from(iri).into() }); self } @@ -291,7 +291,7 @@ impl RuleRecognizer for TriGRecognizer { self } N3Token::IriRef(iri) => { - self.cur_subject.push(NamedNode::new_unchecked(iri.into_inner()).into()); + self.cur_subject.push(NamedNode::from(iri).into()); self.stack.push(TriGState::PredicateObjectList); self } @@ -337,7 +337,7 @@ impl RuleRecognizer for TriGRecognizer { // [7g] labelOrSubject ::= iri | BlankNode TriGState::GraphName => match token { N3Token::IriRef(iri) => { - self.cur_graph = NamedNode::new_unchecked(iri.into_inner()).into(); + self.cur_graph = NamedNode::from(iri).into(); self } N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) { @@ -451,7 +451,7 @@ impl RuleRecognizer for TriGRecognizer { self } N3Token::IriRef(iri) => { - self.cur_predicate.push(NamedNode::new_unchecked(iri.into_inner())); + self.cur_predicate.push(NamedNode::from(iri)); self } N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) { @@ -479,7 +479,7 @@ impl RuleRecognizer for TriGRecognizer { // [137s] BlankNode ::= BLANK_NODE_LABEL | ANON TriGState::Object => match token { N3Token::IriRef(iri) => { - self.cur_object.push(NamedNode::new_unchecked(iri.into_inner()).into()); + self.cur_object.push(NamedNode::from(iri).into()); self.emit_quad(results); self } @@ -632,7 +632,7 @@ impl RuleRecognizer for TriGRecognizer { TriGState::LiteralExpectDatatype { value, emit } => { match token { N3Token::IriRef(datatype) => { - self.cur_object.push(Literal::new_typed_literal(value, NamedNode::new_unchecked(datatype.into_inner())).into()); + self.cur_object.push(Literal::new_typed_literal(value, datatype).into()); if emit { self.emit_quad(results); } @@ -694,7 +694,7 @@ impl RuleRecognizer for TriGRecognizer { self } N3Token::IriRef(iri) => { - self.cur_subject.push(NamedNode::new_unchecked(iri.into_inner()).into()); + self.cur_subject.push(NamedNode::from(iri).into()); self } N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) { @@ -726,7 +726,7 @@ impl RuleRecognizer for TriGRecognizer { self } N3Token::IriRef(iri) => { - self.cur_object.push(NamedNode::new_unchecked(iri.into_inner()).into()); + self.cur_object.push(NamedNode::from(iri).into()); self } N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) { diff --git a/lib/spargebra/src/parser.rs b/lib/spargebra/src/parser.rs index 0dccff3b..32522c5c 100644 --- a/lib/spargebra/src/parser.rs +++ b/lib/spargebra/src/parser.rs @@ -1975,7 +1975,7 @@ parser! { rule String() -> String = STRING_LITERAL_LONG1() / STRING_LITERAL_LONG2() / STRING_LITERAL1() / STRING_LITERAL2() rule iri() -> NamedNode = i:(IRIREF() / PrefixedName()) { - NamedNode::new_unchecked(i.into_inner()) + NamedNode::from(i) } rule PrefixedName() -> Iri = PNAME_LN() / diff --git a/server/src/main.rs b/server/src/main.rs index 5db006b9..aed17921 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1102,13 +1102,11 @@ fn base_url(request: &Request) -> String { } fn resolve_with_base(request: &Request, url: &str) -> Result { - Ok(NamedNode::new_unchecked( - Iri::parse(base_url(request)) - .map_err(bad_request)? - .resolve(url) - .map_err(bad_request)? - .into_inner(), - )) + Ok(Iri::parse(base_url(request)) + .map_err(bad_request)? + .resolve(url) + .map_err(bad_request)? + .into()) } fn url_query(request: &Request) -> &[u8] {