Enum canrun::core::Value

source ·
pub enum Value<T: Unify> {
    Var(LVar<T>),
    Resolved(Rc<T>),
}
Expand description

Contain individual resolved values or variables that can be bound through unification.

Variants§

§

Var(LVar<T>)

A logical variable.

Even though they do not contain a value, they are parameterized with the type they can potentially be bound to. This ensures that they can only be unified with values of the same type.

§

Resolved(Rc<T>)

A resolved value.

When a state is split into an arbitrary number of resolved states, some of the internal data structures often need to be cloned. In an attempt to avoid unnecessary cloning of every value in the state, we wrap it in an Rc so that references can be shared.

Implementations§

source§

impl<T: Unify> Value<T>

source

pub fn new(t: T) -> Value<T>

Create a new logical Value wrapping a T.

Example:
use canrun::Value;
let x: Value<i32> = Value::new(1);
source

pub fn var() -> Value<T>

Create a new logical Value with an unresolved Var.

This is a shorthand for Value::Var(LVar::new()).

Example:
use canrun::Value;
let x: Value<i32> = Value::var();
source

pub fn resolved(&self) -> Option<&T>

Return T if the Value is a resolved.

Example:

use canrun::Value;

let x: Value<i32> = Value::new(1);
assert_eq!(x.resolved(), Some(&1));

Trait Implementations§

source§

impl<T: Unify> Clone for Value<T>

source§

fn clone(&self) -> Self

Returns a copy 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<T: Debug + Unify> Debug for Value<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Unify> From<&LVar<T>> for Value<T>

source§

fn from(var: &LVar<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Unify> From<&Value<T>> for Value<T>

source§

fn from(var: &Value<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Unify> From<LVar<T>> for Value<T>

source§

fn from(var: LVar<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Unify> From<T> for Value<T>

source§

fn from(t: T) -> Self

Converts to this type from the input type.
source§

impl<T: Unify> FromIterator<Value<T>> for LVec<T>

source§

fn from_iter<I: IntoIterator<Item = Value<T>>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T: Hash + Unify> Hash for Value<T>

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<T: PartialEq + Unify> PartialEq<Value<T>> for Value<T>

source§

fn eq(&self, other: &Value<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Unify + Reify> Reify for Value<T>

§

type Reified = <T as Reify>::Reified

The “concrete” type that Self reifies to.
source§

fn reify_in(&self, state: &ReadyState) -> Option<Self::Reified>

Extract a reified Self from a compatible State. This trait is usually used indirectly through the Query trait. Read more
source§

impl<T: Eq + Unify> Eq for Value<T>

source§

impl<T: Unify> StructuralEq for Value<T>

source§

impl<T: Unify> StructuralPartialEq for Value<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Value<T>where T: RefUnwindSafe,

§

impl<T> !Send for Value<T>

§

impl<T> !Sync for Value<T>

§

impl<T> Unpin for Value<T>where T: Unpin,

§

impl<T> UnwindSafe for Value<T>where T: UnwindSafe + RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.