Trait BaseValue

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 + 'static) { ... }
    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§

const MAY_UNBOX: bool = false

Provided Methods§

fn intern(&self, table: &InternTable<Self, Value>) -> Value

fn as_any(&self) -> &(dyn Any + 'static)

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", so this trait is not object safe.

Implementations on Foreign Types§

§

impl BaseValue for &'static str

§

impl BaseValue for bool

§

fn try_unbox(val: Value) -> Option<bool>

§

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);
§

const MAY_UNBOX: bool = true

§

impl BaseValue for i8

§

const MAY_UNBOX: bool = true

§

fn try_unbox(val: Value) -> Option<i8>

§

fn try_box(&self) -> Option<Value>

§

impl BaseValue for i16

§

const MAY_UNBOX: bool = true

§

fn try_unbox(val: Value) -> Option<i16>

§

fn try_box(&self) -> Option<Value>

§

impl BaseValue for i32

§

const MAY_UNBOX: bool = true

§

fn try_unbox(val: Value) -> Option<i32>

§

fn try_box(&self) -> Option<Value>

§

impl BaseValue for i64

§

const MAY_UNBOX: bool = true

§

fn try_box(&self) -> Option<Value>

§

fn try_unbox(val: Value) -> Option<i64>

§

impl BaseValue for isize

§

const MAY_UNBOX: bool = true

§

fn try_box(&self) -> Option<Value>

§

fn try_unbox(val: Value) -> Option<isize>

§

impl BaseValue for u8

§

const MAY_UNBOX: bool = true

§

fn try_unbox(val: Value) -> Option<u8>

§

fn try_box(&self) -> Option<Value>

§

impl BaseValue for u16

§

const MAY_UNBOX: bool = true

§

fn try_unbox(val: Value) -> Option<u16>

§

fn try_box(&self) -> Option<Value>

§

impl BaseValue for u32

§

const MAY_UNBOX: bool = true

§

fn try_unbox(val: Value) -> Option<u32>

§

fn try_box(&self) -> Option<Value>

§

impl BaseValue for u64

§

const MAY_UNBOX: bool = true

§

fn try_box(&self) -> Option<Value>

§

fn try_unbox(val: Value) -> Option<u64>

§

impl BaseValue for ()

§

fn try_unbox(_val: Value) -> Option<()>

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 usize

§

const MAY_UNBOX: bool = true

§

fn try_box(&self) -> Option<Value>

§

fn try_unbox(val: Value) -> Option<usize>

§

impl BaseValue for String

§

impl BaseValue for Ratio<i64>

Implementors§

Source§

impl BaseValue for ResolvedFunction

§

impl<T> BaseValue for Boxed<T>
where T: Hash + Eq + Debug + Clone + Send + Sync + 'static,