Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Node(NodeId),
    String(String),
    Integer(i64),
    Float(f64),
    Boolean(bool),
    DateTime(String),
    Typed {
        value: String,
        datatype: String,
    },
    LangString {
        value: String,
        lang: String,
    },
    Bytes(Vec<u8>),
    Json(Value),
    Null,
}
Expand description

Represents the object of a (subject, predicate, object) triple.

A Value can be either a reference to another node in the graph (creating a link) or a literal value of various types (string, number, boolean, etc.).

§Examples

Creating a string literal:

use aingle_graph::Value;

let val = Value::literal("Alice");
assert!(val.is_literal());
assert_eq!(val.as_string(), Some("Alice"));

Creating a node reference:

use aingle_graph::{Value, NodeId};

let val = Value::node(NodeId::named("user:bob"));
assert!(val.is_node());

Creating numeric values:

use aingle_graph::Value;

let age = Value::integer(30);
assert_eq!(age.as_integer(), Some(30));

let score = Value::float(98.5);
assert_eq!(score.as_float(), Some(98.5));

Creating a typed literal:

use aingle_graph::Value;

let val = Value::typed("2024-01-01", "xsd:date");

Variants§

§

Node(NodeId)

A reference to another node in the graph, linking two subjects together.

§

String(String)

A UTF-8 string literal.

§

Integer(i64)

A 64-bit signed integer literal.

§

Float(f64)

A 64-bit floating-point literal.

§

Boolean(bool)

A boolean literal.

§

DateTime(String)

A date-time literal, typically stored as an ISO 8601 string.

§

Typed

A literal with an explicit datatype URI, similar to RDF typed literals.

Fields

§value: String
§datatype: String
§

LangString

A string literal with a language tag.

Fields

§value: String
§lang: String
§

Bytes(Vec<u8>)

A blob of binary data.

§

Json(Value)

A JSON value, allowing for complex, nested data structures as objects.

§

Null

The null value.

Implementations§

Source§

impl Value

Source

pub fn literal(s: impl Into<String>) -> Self

Creates a new string literal Value.

§Examples
use aingle_graph::Value;

let val = Value::literal("Hello, World!");
assert_eq!(val.as_string(), Some("Hello, World!"));
Source

pub fn node(node: NodeId) -> Self

Creates a Value that is a reference to another NodeId.

This creates a link between two nodes in the graph.

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

let val = Value::node(NodeId::named("user:bob"));
assert!(val.is_node());
assert_eq!(val.as_node(), Some(&NodeId::named("user:bob")));
Source

pub fn integer(n: i64) -> Self

Creates a new integer Value.

§Examples
use aingle_graph::Value;

let val = Value::integer(42);
assert_eq!(val.as_integer(), Some(42));
Source

pub fn float(f: f64) -> Self

Creates a new float Value.

§Examples
use aingle_graph::Value;

let val = Value::float(3.14);
assert_eq!(val.as_float(), Some(3.14));
Source

pub fn boolean(b: bool) -> Self

Creates a new boolean Value.

§Examples
use aingle_graph::Value;

let val = Value::boolean(true);
assert_eq!(val.as_boolean(), Some(true));
Source

pub fn datetime(dt: impl Into<String>) -> Self

Creates a new date-time Value.

Source

pub fn typed(value: impl Into<String>, datatype: impl Into<String>) -> Self

Creates a new typed literal Value.

Typed literals have an associated datatype URI, similar to RDF typed literals.

§Examples
use aingle_graph::Value;

let date = Value::typed("2024-01-01", "xsd:date");
let custom = Value::typed("custom_value", "http://example.org/mytype");
Source

pub fn lang_string(value: impl Into<String>, lang: impl Into<String>) -> Self

Creates a new language-tagged string Value.

Language-tagged strings are useful for internationalization, allowing you to store the same text in multiple languages.

§Examples
use aingle_graph::Value;

let english = Value::lang_string("Hello", "en");
let spanish = Value::lang_string("Hola", "es");
let french = Value::lang_string("Bonjour", "fr");
Source

pub fn bytes(data: Vec<u8>) -> Self

Creates a new bytes Value.

Source

pub fn json(value: Value) -> Self

Creates a new JSON Value.

Source

pub fn null() -> Self

Creates a Null value.

Source

pub fn is_node(&self) -> bool

Returns true if the Value is a Node reference.

Source

pub fn is_literal(&self) -> bool

Returns true if the Value is a literal (i.e., not a Node or Null).

Source

pub fn is_null(&self) -> bool

Returns true if the Value is Null.

Source

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

Returns a reference to the NodeId if the Value is a Node.

Source

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

Returns a string slice if the Value is a string-like literal.

Source

pub fn as_integer(&self) -> Option<i64>

Returns the i64 value if the Value is an Integer.

Source

pub fn as_float(&self) -> Option<f64>

Returns the f64 value if the Value is a Float or can be cast from Integer.

Source

pub fn as_boolean(&self) -> Option<bool>

Returns the bool value if the Value is a Boolean.

Source

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

Serializes the Value to a byte vector for storage.

Source

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

Deserializes a Value from a byte slice.

Source

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

Returns a byte vector suitable for lexicographical sorting in the database indexes.

This method generates a binary representation of the value that can be sorted lexicographically to maintain proper ordering in the database. Different value types are given different type tags to ensure correct cross-type ordering.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

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 Value

Source§

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

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

impl<'de> Deserialize<'de> for Value

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 Value

Source§

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

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

impl From<&str> for Value

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<NodeId> for Value

Source§

fn from(n: NodeId) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(v: Value) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(f: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(n: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(n: i64) -> Self

Converts to this type from the input type.
Source§

impl Hash for Value

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Value

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> 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 PartialOrd for Value

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Value

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 Eq for Value

Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

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>,