Skip to main content

TriplePattern

Struct TriplePattern 

Source
pub struct TriplePattern {
    pub subject: Option<NodeId>,
    pub predicate: Option<Predicate>,
    pub object: Option<Value>,
}
Expand description

A pattern for matching (Subject, Predicate, Object) triples.

A pattern specifies constraints on the components of a triple. Any component can be None, which acts as a wildcard that matches any value.

§Examples

Match all triples with a specific subject:

use aingle_graph::{TriplePattern, NodeId};

let pattern = TriplePattern::subject(NodeId::named("user:alice"));

Match triples with specific subject and predicate:

use aingle_graph::{TriplePattern, NodeId, Predicate};

let pattern = TriplePattern::subject(NodeId::named("user:alice"))
    .with_predicate(Predicate::named("has_name"));

Match all triples (wildcard pattern):

use aingle_graph::TriplePattern;

let pattern = TriplePattern::any();
assert!(pattern.is_wildcard());

Fields§

§subject: Option<NodeId>

An optional constraint on the triple’s subject.

§predicate: Option<Predicate>

An optional constraint on the triple’s predicate.

§object: Option<Value>

An optional constraint on the triple’s object.

Implementations§

Source§

impl TriplePattern

Source

pub fn any() -> Self

Creates a new pattern that matches any triple.

This is equivalent to a wildcard pattern with no constraints.

§Examples
use aingle_graph::TriplePattern;

let pattern = TriplePattern::any();
assert!(pattern.is_wildcard());
Source

pub fn subject(subject: NodeId) -> Self

Creates a new pattern that matches a specific subject.

§Examples
use aingle_graph::{TriplePattern, NodeId};

let pattern = TriplePattern::subject(NodeId::named("user:alice"));
Source

pub fn predicate(predicate: Predicate) -> Self

Creates a new pattern that matches a specific predicate.

Source

pub fn object(object: Value) -> Self

Creates a new pattern that matches a specific object.

Source

pub fn with_subject(self, subject: NodeId) -> Self

Adds a subject constraint to the pattern.

Source

pub fn with_predicate(self, predicate: Predicate) -> Self

Adds a predicate constraint to the pattern.

Source

pub fn with_object(self, object: Value) -> Self

Adds an object constraint to the pattern.

Source

pub fn matches(&self, triple: &Triple) -> bool

Returns true if the given Triple matches this pattern.

A triple matches the pattern if all non-None constraints are satisfied.

§Examples
use aingle_graph::{Triple, TriplePattern, NodeId, Predicate, Value};

let triple = Triple::new(
    NodeId::named("user:alice"),
    Predicate::named("has_name"),
    Value::literal("Alice"),
);

let pattern = TriplePattern::subject(NodeId::named("user:alice"));
assert!(pattern.matches(&triple));

let wrong_pattern = TriplePattern::subject(NodeId::named("user:bob"));
assert!(!wrong_pattern.matches(&triple));
Source

pub fn is_exact(&self) -> bool

Returns true if all components (subject, predicate, object) of the pattern are specified.

Source

pub fn is_wildcard(&self) -> bool

Returns true if the pattern is a wildcard (all components are None).

Trait Implementations§

Source§

impl Clone for TriplePattern

Source§

fn clone(&self) -> TriplePattern

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TriplePattern

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TriplePattern

Source§

fn default() -> TriplePattern

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.