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.
LangString
A string literal with a language tag.
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
impl Value
Sourcepub fn lang_string(value: impl Into<String>, lang: impl Into<String>) -> Self
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");Sourcepub fn is_literal(&self) -> bool
pub fn is_literal(&self) -> bool
Returns true if the Value is a literal (i.e., not a Node or Null).
Sourcepub fn as_node(&self) -> Option<&NodeId>
pub fn as_node(&self) -> Option<&NodeId>
Returns a reference to the NodeId if the Value is a Node.
Sourcepub fn as_string(&self) -> Option<&str>
pub fn as_string(&self) -> Option<&str>
Returns a string slice if the Value is a string-like literal.
Sourcepub fn as_integer(&self) -> Option<i64>
pub fn as_integer(&self) -> Option<i64>
Returns the i64 value if the Value is an Integer.
Sourcepub fn as_float(&self) -> Option<f64>
pub fn as_float(&self) -> Option<f64>
Returns the f64 value if the Value is a Float or can be cast from Integer.
Sourcepub fn as_boolean(&self) -> Option<bool>
pub fn as_boolean(&self) -> Option<bool>
Returns the bool value if the Value is a Boolean.
Sourcepub fn from_bytes(bytes: &[u8]) -> Option<Self>
pub fn from_bytes(bytes: &[u8]) -> Option<Self>
Deserializes a Value from a byte slice.
Sourcepub fn sort_key(&self) -> Vec<u8> ⓘ
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.