pub trait BaseValue:
Clone
+ Hash
+ Eq
+ Any
+ Debug
+ Send
+ Sync {
const MAY_UNBOX: bool = false;
// Provided methods
fn intern(&self, table: &InternTable<Self, Value>) -> Value { ... }
fn as_any(&self) -> &dyn Any { ... }
fn try_box(&self) -> Option<Value> { ... }
fn try_unbox(_val: Value) -> Option<Self> { ... }
}Expand description
A simple data type that can be interned in a database.
Most callers can simply implement this trait on their desired type, with no overrides needed.
For types that are particularly small, users can override BaseValue::try_box and BaseValue::try_unbox
methods and set BaseValue::MAY_UNBOX to true to allow the Rust value to be stored in-place in a
Value.
Regardless, all base value types should be registered in a BaseValues instance using the
BaseValues::register_type method before they can be used in the database.
Provided Associated Constants§
Provided Methods§
fn intern(&self, table: &InternTable<Self, Value>) -> Value
fn as_any(&self) -> &dyn Any
fn try_box(&self) -> Option<Value>
fn try_unbox(_val: Value) -> Option<Self>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
impl BaseValue for &'static str
Source§impl BaseValue for ()
impl BaseValue for ()
Source§fn try_unbox(_val: Value) -> Option<Self>
fn try_unbox(_val: Value) -> Option<Self>
To optimize storage, we map Value 0 to unit type.
use egglog_core_relations::BaseValue;
let unit_value = ().try_box().unwrap();
assert_eq!(<()>::try_unbox(unit_value).unwrap(), ());const MAY_UNBOX: bool = true
fn try_box(&self) -> Option<Value>
impl BaseValue for Rational64
impl BaseValue for String
Source§impl BaseValue for bool
impl BaseValue for bool
Source§fn try_box(&self) -> Option<Value>
fn try_box(&self) -> Option<Value>
To optimize storage, we map Value 1 to true and 0 to false in the implementation.
As an example, the subsumed column of a table has type bool.
use egglog_core_relations::BaseValue;
let true_value = true.try_box().unwrap();
let false_value = false.try_box().unwrap();
assert_eq!(bool::try_unbox(true_value).unwrap(), true);
assert_eq!(bool::try_unbox(false_value).unwrap(), false);