Trait PQLFn

Source
pub trait PQLFn:
    Debug
    + Send
    + Sync
    + PQLFnRtn
    + PQLFnArgs
    + PQLFnEval { }
Expand description

Trait for functions to be used in vm

Generated by fn_macro::pqlfn Example:

#[pqlfn(arg, rtn, eval)]
pub fn hand_ranks(hand: &Hand, _street: PQLStreet) -> PQLRankSet;

pub trait PQLFnArgs {
    fn arg_types(&self) -> &[PQLType] {
        &[PQLType::Player, PQLType::Street]
    }
}

pub trait PQLFnRtn {
    fn rtn_type(&self) -> PQLType {
        PQLType::RankSet
    }
}

pub trait PQLFnEval {
    fn evaluate(
        &self,
        buffer: &mut VmBuffer,
        store: &mut VmStore,
        stack: &mut VmStack,
    ) -> Result<VmStackValue, PQLError> {
        Ok(self(arg_range(buffer, store, stack), (&*buffer).into()).into())
    }
}

each pqlfn also generates a match arm for FromStr of &dyn PQLFn

  "handranks" => Ok(&(hand_ranks as fn(&Hand, PQLStreet) -> PQLRankSet)),

Trait Implementations§

Source§

impl From<&'static dyn PQLFn> for VmInstruction

Source§

fn from(value: &'static dyn PQLFn) -> Self

Converts to this type from the input type.
Source§

impl FromStr for &dyn PQLFn

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more

Implementors§

Source§

impl<T> PQLFn for T