Skip to main content

Triple

Struct Triple 

Source
pub struct Triple {
    pub subject: NodeId,
    pub predicate: Predicate,
    pub object: Value,
    pub meta: TripleMeta,
}
Expand description

A semantic triple, representing a single fact as a (Subject, Predicate, Object) statement.

A triple is the fundamental unit of data in the graph database. It represents a relationship between a subject and an object through a predicate.

§Examples

Creating a triple with a literal value:

use aingle_graph::{Triple, NodeId, Predicate, Value};

let triple = Triple::new(
    NodeId::named("user:alice"),
    Predicate::named("has_age"),
    Value::integer(30),
);

Creating a triple that links two nodes:

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

let triple = Triple::link(
    NodeId::named("user:alice"),
    Predicate::named("knows"),
    NodeId::named("user:bob"),
);

Creating a triple with metadata:

use aingle_graph::{Triple, TripleMeta, NodeId, Predicate, Value};

let meta = TripleMeta::new()
    .with_author(NodeId::named("system"))
    .with_source("import");

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

Fields§

§subject: NodeId

The subject of the triple (the “thing” being described).

§predicate: Predicate

The predicate (the relationship type).

§object: Value

The object (the value or related node).

§meta: TripleMeta

Associated metadata, providing context and provenance for the triple.

Implementations§

Source§

impl Triple

Source

pub fn new(subject: NodeId, predicate: Predicate, object: Value) -> Self

Creates a new Triple with default metadata.

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

let triple = Triple::new(
    NodeId::named("user:alice"),
    Predicate::named("has_email"),
    Value::literal("alice@example.com"),
);
Source

pub fn with_meta( subject: NodeId, predicate: Predicate, object: Value, meta: TripleMeta, ) -> Self

Creates a new Triple with the specified metadata.

Source

pub fn literal( subject: impl Into<NodeId>, predicate: impl Into<Predicate>, value: impl Into<String>, ) -> Self
where NodeId: From<String>,

A convenience method to create a triple with a literal string object.

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

let triple = Triple::literal("user:alice", "has_name", "Alice Smith");
assert_eq!(triple.object.as_string(), Some("Alice Smith"));

A convenience method to create a triple that links two nodes.

This creates a relationship between two nodes in the graph.

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

let triple = Triple::link(
    NodeId::named("user:alice"),
    "knows",
    NodeId::named("user:bob"),
);

assert!(triple.is_link());
assert_eq!(triple.object_node(), Some(&NodeId::named("user:bob")));
Source

pub fn id(&self) -> TripleId

Generates the unique, content-based ID for this triple.

The ID is deterministic - identical triples will always produce the same ID.

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

let triple = Triple::new(
    NodeId::named("alice"),
    Predicate::named("age"),
    Value::integer(30),
);

let id = triple.id();
println!("Triple ID: {}", id);

Returns true if the triple’s object is a reference to another node.

Source

pub fn is_literal(&self) -> bool

Returns true if the triple’s object is a literal value.

Source

pub fn object_node(&self) -> Option<&NodeId>

Returns the object as a NodeId if it is a node reference.

Source

pub fn object_string(&self) -> Option<&str>

Returns the object as a string slice if it is a string-like literal.

Source

pub fn to_ntriples(&self) -> String

Formats the triple into the N-Triples standard string format.

Source

pub fn to_bytes(&self) -> Vec<u8>

Serializes the Triple to a byte vector for storage.

Source

pub fn from_bytes(bytes: &[u8]) -> Option<Self>

Deserializes a Triple from a byte slice.

Source

pub fn index_keys(&self) -> TripleIndexKeys

Creates a set of pre-computed, lexicographically sortable keys for database indexing.

Trait Implementations§

Source§

impl Clone for Triple

Source§

fn clone(&self) -> Triple

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 Triple

Source§

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

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

impl<'de> Deserialize<'de> for Triple

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Triple

Source§

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

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

impl PartialEq for Triple

Source§

fn eq(&self, other: &Triple) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Triple

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Triple

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,