pub struct DataFactory;Expand description
Stateless factory for constructing RDF terms, triples and quads.
Every method is pub and fn (not self); the struct itself needs no
instance – it is used as a namespace.
Implementations§
Source§impl DataFactory
impl DataFactory
Sourcepub fn named_node(iri: impl Into<String>) -> Result<NamedNode>
pub fn named_node(iri: impl Into<String>) -> Result<NamedNode>
Create a NamedNode from an IRI string, validating it.
Returns OxirsError::Parse if the string is not a well-formed IRI.
use oxirs_core::data_factory::DataFactory;
let n = DataFactory::named_node("http://example.org/s").expect("valid IRI for named node");
assert_eq!(n.as_str(), "http://example.org/s");Sourcepub fn blank_node() -> BlankNode
pub fn blank_node() -> BlankNode
Create a BlankNode with an auto-generated unique identifier.
use oxirs_core::data_factory::DataFactory;
let b1 = DataFactory::blank_node();
let b2 = DataFactory::blank_node();
assert_ne!(b1.as_str(), b2.as_str());Sourcepub fn blank_node_with_id(id: impl Into<String>) -> BlankNode
pub fn blank_node_with_id(id: impl Into<String>) -> BlankNode
Create a BlankNode with a specific local identifier.
The identifier must match [a-zA-Z0-9_][a-zA-Z0-9_.-]*; invalid
strings are silently replaced with a generated one.
use oxirs_core::data_factory::DataFactory;
let b = DataFactory::blank_node_with_id("my-node");
assert_eq!(b.as_str(), "my-node");Sourcepub fn literal(value: impl Into<String>) -> Literal
pub fn literal(value: impl Into<String>) -> Literal
Create a plain (xsd:string) Literal.
use oxirs_core::data_factory::DataFactory;
let l = DataFactory::literal("hello");
assert_eq!(l.value(), "hello");Sourcepub fn typed_literal(value: impl Into<String>, datatype: NamedNode) -> Literal
pub fn typed_literal(value: impl Into<String>, datatype: NamedNode) -> Literal
Create an explicitly-typed Literal.
use oxirs_core::data_factory::{DataFactory, xsd_types};
let l = DataFactory::typed_literal("42", xsd_types::integer());
assert_eq!(l.value(), "42");Sourcepub fn language_literal(
value: impl Into<String>,
lang: impl Into<String>,
) -> Result<Literal>
pub fn language_literal( value: impl Into<String>, lang: impl Into<String>, ) -> Result<Literal>
Create a language-tagged Literal (BCP 47 language tag).
Returns OxirsError::Parse if lang is not a valid BCP 47 tag.
use oxirs_core::data_factory::DataFactory;
let l = DataFactory::language_literal("Bonjour", "fr").expect("valid language literal");
assert_eq!(l.language(), Some("fr"));Sourcepub fn triple(subject: Subject, predicate: NamedNode, object: Object) -> Triple
pub fn triple(subject: Subject, predicate: NamedNode, object: Object) -> Triple
Create a Triple from subject, predicate, and object.
use oxirs_core::data_factory::DataFactory;
use oxirs_core::model::{Subject, Object};
let s = DataFactory::named_node("http://example.org/s").expect("valid IRI for named node");
let p = DataFactory::named_node("http://example.org/p").expect("valid IRI for named node");
let o = DataFactory::named_node("http://example.org/o").expect("valid IRI for named node");
let triple = DataFactory::triple(s.into(), p, o.into());Sourcepub fn quad(
subject: Subject,
predicate: NamedNode,
object: Object,
graph: GraphName,
) -> Quad
pub fn quad( subject: Subject, predicate: NamedNode, object: Object, graph: GraphName, ) -> Quad
Create a Quad from subject, predicate, object, and graph name.
Use Self::default_graph() for the default graph.
use oxirs_core::data_factory::DataFactory;
use oxirs_core::model::{Subject, Object};
let s = DataFactory::named_node("http://example.org/s").expect("valid IRI for named node");
let p = DataFactory::named_node("http://example.org/p").expect("valid IRI for named node");
let o = DataFactory::named_node("http://example.org/o").expect("valid IRI for named node");
let g = DataFactory::default_graph();
let quad = DataFactory::quad(s.into(), p, o.into(), g);Sourcepub fn default_graph() -> GraphName
pub fn default_graph() -> GraphName
Return the default GraphName.
Sourcepub fn named_graph(iri: impl Into<String>) -> Result<GraphName>
pub fn named_graph(iri: impl Into<String>) -> Result<GraphName>
Create a named-graph GraphName from a validated IRI.
Returns OxirsError::Parse if the string is not a well-formed IRI.
Sourcepub fn validate_iri(iri: &str) -> Result<()>
pub fn validate_iri(iri: &str) -> Result<()>
Validate an IRI string without constructing a NamedNode.
use oxirs_core::data_factory::DataFactory;
assert!(DataFactory::validate_iri("http://example.org/").is_ok());
assert!(DataFactory::validate_iri("not an IRI").is_err());Sourcepub fn validate_lang_tag(lang: &str) -> Result<()>
pub fn validate_lang_tag(lang: &str) -> Result<()>
Validate a BCP 47 language tag string.
use oxirs_core::data_factory::DataFactory;
assert!(DataFactory::validate_lang_tag("en").is_ok());
assert!(DataFactory::validate_lang_tag("en-US").is_ok());
assert!(DataFactory::validate_lang_tag("zh-Hans-CN").is_ok());
assert!(DataFactory::validate_lang_tag("").is_err());Auto Trait Implementations§
impl Freeze for DataFactory
impl RefUnwindSafe for DataFactory
impl Send for DataFactory
impl Sync for DataFactory
impl Unpin for DataFactory
impl UnsafeUnpin for DataFactory
impl UnwindSafe for DataFactory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more