Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Null,
    Bool(bool),
    Int(i64),
    Float(f64),
    String(String),
    List(Vec<Value>),
    Map(ValueMap),
    Vertex(VertexId),
    Edge(EdgeId),
    Point(Point),
    Polygon(Polygon),
}
Expand description

A dynamic value type for graph properties and traversal results.

Value is Interstellar’s universal data type, capable of representing any property value or traversal result. It’s similar to JSON but extended with graph-specific types for vertex and edge references.

§Variants

VariantRust TypeDescription
Null-Absence of a value
BoolboolBoolean true/false
Inti6464-bit signed integer
Floatf6464-bit floating point
StringStringUTF-8 text
ListVec<Value>Ordered collection
MapHashMap<String, Value>Key-value pairs
VertexVertexIdReference to a vertex
EdgeEdgeIdReference to an edge

§Type Conversions

Value implements From for many common types:

use interstellar::prelude::*;

// Primitives
let _: Value = true.into();
let _: Value = 42i64.into();
let _: Value = 3.14f64.into();
let _: Value = "hello".into();

// Graph elements
let _: Value = VertexId(1).into();
let _: Value = EdgeId(2).into();

§Type Checking and Extraction

Use the as_* methods to safely extract typed values:

use interstellar::prelude::*;

let val: Value = 42i64.into();

// Type-safe extraction
if let Some(n) = val.as_i64() {
    println!("Got integer: {}", n);
}

// Type checking
assert!(!val.is_null());
assert!(!val.is_vertex());

§Hashing

Value implements Hash, allowing it to be used in hash-based collections. Map values are hashed in sorted key order to ensure consistent hashing regardless of insertion order.

use interstellar::prelude::*;
use std::collections::HashSet;

let mut seen: HashSet<Value> = HashSet::new();
seen.insert(42i64.into());
seen.insert("hello".into());

Variants§

§

Null

The null/absent value.

§

Bool(bool)

A boolean value.

§

Int(i64)

A 64-bit signed integer.

§

Float(f64)

A 64-bit floating-point number.

§

String(String)

A UTF-8 string.

§

List(Vec<Value>)

An ordered list of values.

§

Map(ValueMap)

A map of string keys to values. Iteration order is the insertion order.

§

Vertex(VertexId)

A vertex reference (for traversal).

§

Edge(EdgeId)

An edge reference (for traversal).

§

Point(Point)

A geospatial point (WGS84 longitude/latitude).

§

Polygon(Polygon)

A geospatial polygon (WGS84, simple closed ring, no holes).

Implementations§

Source§

impl Value

Source

pub fn serialize(&self, buf: &mut Vec<u8>)

Serialize this value to a compact binary format.

The binary format uses a type tag byte followed by the value data. This format is suitable for persistence and network transmission.

§Format
TagTypeData
0x00Null(none)
0x01Bool(false)(none)
0x02Bool(true)(none)
0x03Int8 bytes (little-endian i64)
0x04Float8 bytes (little-endian f64)
0x05String4-byte length + UTF-8 bytes
0x06List4-byte count + serialized items
0x07Map4-byte count + (key, value) pairs
0x08Vertex8 bytes (little-endian u64)
0x09Edge8 bytes (little-endian u64)
§Example
use interstellar::prelude::*;

let value = Value::Int(42);
let mut buf = Vec::new();
value.serialize(&mut buf);

// Deserialize it back
let mut pos = 0;
let parsed = Value::deserialize(&buf, &mut pos).unwrap();
assert_eq!(parsed, value);
Source

pub fn deserialize(buf: &[u8], pos: &mut usize) -> Option<Value>

Deserialize a value from a binary buffer.

Reads a value starting at position pos in the buffer, advancing pos past the consumed bytes. Returns None if the buffer is malformed or truncated.

§Arguments
  • buf - The byte buffer to read from
  • pos - Mutable position indicator, updated to point past the read value
§Returns

Some(Value) if deserialization succeeds, None if the data is invalid.

§Example
use interstellar::prelude::*;

// Serialize a value
let original = Value::String("hello".to_string());
let mut buf = Vec::new();
original.serialize(&mut buf);

// Deserialize it
let mut pos = 0;
let parsed = Value::deserialize(&buf, &mut pos).unwrap();
assert_eq!(parsed, original);
assert_eq!(pos, buf.len()); // Position advanced to end
Source

pub fn to_comparable(&self) -> ComparableValue

Convert this value to a comparable version with total ordering.

Returns a ComparableValue that mirrors this value but implements Ord, enabling sorting and use in ordered collections.

§Example
use interstellar::prelude::*;

let values = vec![
    Value::Int(3),
    Value::Int(1),
    Value::Int(2),
];

let mut comparable: Vec<_> = values.iter()
    .map(Value::to_comparable)
    .collect();
comparable.sort();

// Now sorted: [Int(1), Int(2), Int(3)]
Source

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

Extract the value as a boolean, if it is one.

Returns Some(bool) if this is a Bool variant, None otherwise.

§Example
use interstellar::prelude::*;

assert_eq!(Value::Bool(true).as_bool(), Some(true));
assert_eq!(Value::Int(1).as_bool(), None);
Source

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

Extract the value as an i64 integer, if it is one.

Returns Some(i64) if this is an Int variant, None otherwise.

§Example
use interstellar::prelude::*;

assert_eq!(Value::Int(42).as_i64(), Some(42));
assert_eq!(Value::Float(42.0).as_i64(), None); // Type mismatch
Source

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

Extract the value as an f64 float, if it is one.

Returns Some(f64) if this is a Float variant, None otherwise.

§Example
use interstellar::prelude::*;

assert_eq!(Value::Float(3.14).as_f64(), Some(3.14));
assert_eq!(Value::Int(3).as_f64(), None); // Type mismatch
Source

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

Extract the value as a string slice, if it is one.

Returns Some(&str) if this is a String variant, None otherwise.

§Example
use interstellar::prelude::*;

let val = Value::String("hello".to_string());
assert_eq!(val.as_str(), Some("hello"));
assert_eq!(Value::Int(42).as_str(), None);
Source

pub fn as_list(&self) -> Option<&Vec<Value>>

Extract the value as a list reference, if it is one.

Returns Some(&Vec<Value>) if this is a List variant, None otherwise.

§Example
use interstellar::prelude::*;

let val = Value::List(vec![Value::Int(1), Value::Int(2)]);
if let Some(items) = val.as_list() {
    assert_eq!(items.len(), 2);
}
Source

pub fn as_map(&self) -> Option<&ValueMap>

Extract the value as a map reference, if it is one.

Returns Some(&ValueMap) if this is a Map variant, None otherwise. The returned map preserves insertion order.

§Example
use interstellar::prelude::*;
use interstellar::value::ValueMap;

let mut map = ValueMap::new();
map.insert("name".to_string(), Value::String("Alice".to_string()));
let val = Value::Map(map);

if let Some(m) = val.as_map() {
    assert!(m.contains_key("name"));
}
Source

pub fn is_null(&self) -> bool

Check if this value is null.

Returns true if this is the Null variant, false otherwise.

§Example
use interstellar::prelude::*;

assert!(Value::Null.is_null());
assert!(!Value::Int(0).is_null());
assert!(!Value::String("".to_string()).is_null());
Source

pub fn as_vertex_id(&self) -> Option<VertexId>

Extract the value as a vertex ID, if it is one.

Returns Some(VertexId) if this is a Vertex variant, None otherwise.

§Example
use interstellar::prelude::*;

let val = Value::Vertex(VertexId(42));
assert_eq!(val.as_vertex_id(), Some(VertexId(42)));
assert_eq!(Value::Edge(EdgeId(42)).as_vertex_id(), None);
Source

pub fn as_edge_id(&self) -> Option<EdgeId>

Extract the value as an edge ID, if it is one.

Returns Some(EdgeId) if this is an Edge variant, None otherwise.

§Example
use interstellar::prelude::*;

let val = Value::Edge(EdgeId(99));
assert_eq!(val.as_edge_id(), Some(EdgeId(99)));
assert_eq!(Value::Vertex(VertexId(99)).as_edge_id(), None);
Source

pub fn is_vertex(&self) -> bool

Check if this value is a vertex reference.

Returns true if this is a Vertex variant, false otherwise.

§Example
use interstellar::prelude::*;

assert!(Value::Vertex(VertexId(1)).is_vertex());
assert!(!Value::Edge(EdgeId(1)).is_vertex());
assert!(!Value::Int(1).is_vertex());
Source

pub fn is_edge(&self) -> bool

Check if this value is an edge reference.

Returns true if this is an Edge variant, false otherwise.

§Example
use interstellar::prelude::*;

assert!(Value::Edge(EdgeId(1)).is_edge());
assert!(!Value::Vertex(VertexId(1)).is_edge());
assert!(!Value::Int(1).is_edge());
Source

pub fn as_point(&self) -> Option<Point>

Extract the value as a geospatial point, if it is one.

Source

pub fn as_polygon(&self) -> Option<&Polygon>

Extract the value as a geospatial polygon reference, if it is one.

Source

pub fn is_point(&self) -> bool

Check if this value is a geospatial point.

Source

pub fn is_polygon(&self) -> bool

Check if this value is a geospatial polygon.

Source

pub fn discriminant(&self) -> u8

Returns the type discriminant (tag) for this value.

The discriminant is the type tag byte used in the binary serialization format. This is useful for storage backends that need to know the value type without fully deserializing it.

§Discriminant Values
DiscriminantType
0x00Null
0x01Bool(false)
0x02Bool(true)
0x03Int
0x04Float
0x05String
0x06List
0x07Map
0x08Vertex
0x09Edge
§Example
use interstellar::prelude::*;

assert_eq!(Value::Null.discriminant(), 0x00);
assert_eq!(Value::Bool(false).discriminant(), 0x01);
assert_eq!(Value::Bool(true).discriminant(), 0x02);
assert_eq!(Value::Int(42).discriminant(), 0x03);
assert_eq!(Value::Float(3.14).discriminant(), 0x04);
assert_eq!(Value::String("hello".to_string()).discriminant(), 0x05);
assert_eq!(Value::List(vec![]).discriminant(), 0x06);

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 From<&Value> for PathValue

Source§

fn from(value: &Value) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Value

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<EdgeId> for Value

Source§

fn from(id: EdgeId) -> Self

Converts to this type from the input type.
Source§

impl From<HashMap<String, Value>> for Value

Source§

fn from(map: HashMap<String, Value>) -> Self

Converts to this type from the input type.
Source§

impl From<IndexMap<String, Value>> for Value

Source§

fn from(map: ValueMap) -> Self

Converts to this type from the input type.
Source§

impl From<Point> for Value

Source§

fn from(p: Point) -> Self

Converts to this type from the input type.
Source§

impl From<Polygon> for Value

Source§

fn from(p: Polygon) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for OptionKey

Source§

fn from(v: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for PathValue

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(values: Vec<Value>) -> Self

Converts to this type from the input type.
Source§

impl From<VertexId> for Value

Source§

fn from(id: VertexId) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(value: u64) -> 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 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 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

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