Skip to main content

DataFactory

Struct DataFactory 

Source
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

Source

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");
Source

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());
Source

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");
Source

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");
Source

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");
Source

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"));
Source

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());
Source

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);
Source

pub fn default_graph() -> GraphName

Return the default GraphName.

Source

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.

Source

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());
Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,