BaseValue

Trait BaseValue 

Source
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§

Source

const MAY_UNBOX: bool = false

Provided Methods§

Source

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

Source

fn as_any(&self) -> &dyn Any

Source

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

Source

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§

Source§

impl BaseValue for &'static str

Source§

impl BaseValue for bool

Source§

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

Source§

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

const MAY_UNBOX: bool = true

Source§

impl BaseValue for i8

Source§

const MAY_UNBOX: bool = true

Source§

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

Source§

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

Source§

impl BaseValue for i16

Source§

const MAY_UNBOX: bool = true

Source§

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

Source§

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

Source§

impl BaseValue for i32

Source§

const MAY_UNBOX: bool = true

Source§

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

Source§

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

Source§

impl BaseValue for i64

Source§

const MAY_UNBOX: bool = true

Source§

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

Source§

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

Source§

impl BaseValue for isize

Source§

const MAY_UNBOX: bool = true

Source§

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

Source§

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

Source§

impl BaseValue for u8

Source§

const MAY_UNBOX: bool = true

Source§

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

Source§

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

Source§

impl BaseValue for u16

Source§

const MAY_UNBOX: bool = true

Source§

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

Source§

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

Source§

impl BaseValue for u32

Source§

const MAY_UNBOX: bool = true

Source§

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

Source§

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

Source§

impl BaseValue for u64

Source§

const MAY_UNBOX: bool = true

Source§

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

Source§

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

Source§

impl BaseValue for ()

Source§

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(), ());
Source§

const MAY_UNBOX: bool = true

Source§

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

Source§

impl BaseValue for usize

Source§

const MAY_UNBOX: bool = true

Source§

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

Source§

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

Source§

impl BaseValue for String

Source§

impl BaseValue for Rational64

Implementors§

Source§

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