ConstantResolver

Struct ConstantResolver 

Source
pub struct ConstantResolver<S, T>
where S: ResolverState,
{ /* private fields */ }
Expand description

A resolver that always returns the same value regardless of the variable or function name.

§Advantages

  • Best performance between all resolvers.

§Disadvantages

  • Always returns the same value regardless of the variable or function name.

§Examples

use fee::prelude::*;
use fee::{ EmptyResolver, ConstantResolver };

let expr = "x + y";

let var_resolver = ConstantResolver::new(1.0);
let context = Context::new(var_resolver, EmptyResolver::new());
let mut stack = Vec::new();

let expr = Expr::compile(expr, &context).unwrap();
let result = expr.eval(&context, &mut stack).unwrap();
assert_eq!(result, 2.0);

Implementations§

Source§

impl<T> ConstantResolver<Unlocked, T>

Source

pub fn new(value: T) -> Self

Source§

impl<S, T> ConstantResolver<S, T>
where S: ResolverState,

Source

pub fn set(&mut self, value: T)

Trait Implementations§

Source§

impl<S, T> Resolver<S, T> for ConstantResolver<S, T>
where S: ResolverState,

Source§

fn resolve(&self, _name: &str) -> Option<&T>

Auto Trait Implementations§

§

impl<S, T> Freeze for ConstantResolver<S, T>
where T: Freeze, S: Freeze,

§

impl<S, T> RefUnwindSafe for ConstantResolver<S, T>

§

impl<S, T> Send for ConstantResolver<S, T>
where T: Send, S: Send,

§

impl<S, T> Sync for ConstantResolver<S, T>
where T: Sync, S: Sync,

§

impl<S, T> Unpin for ConstantResolver<S, T>
where T: Unpin, S: Unpin,

§

impl<S, T> UnwindSafe for ConstantResolver<S, T>
where T: UnwindSafe, S: UnwindSafe,

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> 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, 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.