pub struct FunctionObject {
pub id: FunctionId,
pub symbol: Symbol,
pub cases: Vec<FunctionCase>,
}Expand description
A callable function object: a named set of shape-typed overload cases with selection driven by case priority and argument match score.
Fields§
§id: FunctionIdStable function identifier.
symbol: SymbolSymbol naming the function.
cases: Vec<FunctionCase>Overload cases in registration order.
Implementations§
Source§impl FunctionObject
impl FunctionObject
Sourcepub fn new(
id: FunctionId,
symbol: Symbol,
cases: Vec<FunctionCase>,
) -> FunctionObject
pub fn new( id: FunctionId, symbol: Symbol, cases: Vec<FunctionCase>, ) -> FunctionObject
Build a function object from an id, symbol, and its overload cases.
Sourcepub fn select_case<'a>(
&'a self,
cx: &mut Cx,
prepared: &PreparedArgs,
) -> Result<SelectedCase<'a>, Error>
pub fn select_case<'a>( &'a self, cx: &mut Cx, prepared: &PreparedArgs, ) -> Result<SelectedCase<'a>, Error>
Pick the overload case that best matches the prepared arguments.
Cases whose argument shape accepts the arguments are ordered by priority
first, then by proven argument-shape specificity (the subshape lattice),
and only then by additive match score: a case whose argument shape is a
proven subshape of another’s is strictly more specific and wins even at
an equal or lower score. Returns Error::NoMatchingOverload when
nothing matches and Error::AmbiguousOverload when two top cases
remain unordered (equal priority, neither shape subsumes the other, and
equal score).
Sourcepub fn combined_args_shape(&self) -> Option<Arc<dyn Shape>>
pub fn combined_args_shape(&self) -> Option<Arc<dyn Shape>>
Shape accepting any case’s arguments: the lone case’s shape, or a
one-of over every case. None when the function has no cases.
Sourcepub fn combined_result_shape(&self) -> Option<Arc<dyn Shape>>
pub fn combined_result_shape(&self) -> Option<Arc<dyn Shape>>
Shape covering every case’s result, or None if any case omits a
result shape. A single result is returned directly; many become a
one-of.
Sourcepub fn declared_demand(&self, index: usize) -> Option<Demand>
pub fn declared_demand(&self, index: usize) -> Option<Demand>
Evaluation demand declared for argument index across all cases.
Returns the shared demand when every case agrees, Demand::Value when
they disagree, and None when no case declares that position.
Sourcepub fn declared_demands(&self) -> Vec<Demand>
pub fn declared_demands(&self) -> Vec<Demand>
Per-position demands for the call, sized to the widest case and
defaulting unspecified positions to Demand::Value.
Trait Implementations§
Source§impl Callable for FunctionObject
impl Callable for FunctionObject
Source§fn call(&self, cx: &mut Cx, args: Args) -> Result<Value, Error>
fn call(&self, cx: &mut Cx, args: Args) -> Result<Value, Error>
Args.Source§fn browse_args_shape(&self, _cx: &mut Cx) -> Result<Option<Value>, Error>
fn browse_args_shape(&self, _cx: &mut Cx) -> Result<Option<Value>, Error>
Source§impl Clone for FunctionObject
impl Clone for FunctionObject
Source§fn clone(&self) -> FunctionObject
fn clone(&self) -> FunctionObject
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Object for FunctionObject
impl Object for FunctionObject
Source§fn display(&self, _cx: &mut Cx) -> Result<String, Error>
fn display(&self, _cx: &mut Cx) -> Result<String, Error>
Source§fn header(&self) -> &ObjectHeader
fn header(&self) -> &ObjectHeader
Source§fn op(&self, _key: &OpKey) -> Option<&dyn Op>
fn op(&self, _key: &OpKey) -> Option<&dyn Op>
key, if any.Source§impl ObjectCompat for FunctionObject
impl ObjectCompat for FunctionObject
Source§fn class(&self, cx: &mut Cx) -> Result<Value, Error>
fn class(&self, cx: &mut Cx) -> Result<Value, Error>
Source§fn as_table(&self, cx: &mut Cx) -> Result<Value, Error>
fn as_table(&self, cx: &mut Cx) -> Result<Value, Error>
Source§fn as_callable(&self) -> Option<&dyn Callable>
fn as_callable(&self) -> Option<&dyn Callable>
Source§fn as_read_constructor(&self) -> Option<&dyn ReadConstructor>
fn as_read_constructor(&self) -> Option<&dyn ReadConstructor>
Source§fn as_object_encoder(&self) -> Option<&dyn ObjectEncode>
fn as_object_encoder(&self) -> Option<&dyn ObjectEncode>
Source§fn as_number_domain(&self) -> Option<&(dyn NumberDomain + 'static)>
fn as_number_domain(&self) -> Option<&(dyn NumberDomain + 'static)>
Source§fn as_number_value(&self) -> Option<&dyn NumberValue>
fn as_number_value(&self) -> Option<&dyn NumberValue>
Source§fn as_eval_fabric(&self) -> Option<&dyn EvalFabric>
fn as_eval_fabric(&self) -> Option<&dyn EvalFabric>
Source§fn as_sequence(&self) -> Option<&dyn Sequence>
fn as_sequence(&self) -> Option<&dyn Sequence>
Source§fn as_list(&self) -> Option<&(dyn ListValue + 'static)>
fn as_list(&self) -> Option<&(dyn ListValue + 'static)>
Source§fn as_table_impl(&self) -> Option<&(dyn Table + 'static)>
fn as_table_impl(&self) -> Option<&(dyn Table + 'static)>
Source§fn as_dir(&self) -> Option<&(dyn Dir + 'static)>
fn as_dir(&self) -> Option<&(dyn Dir + 'static)>
Source§fn as_expr(&self, cx: &mut Cx) -> Result<Expr, Error>
fn as_expr(&self, cx: &mut Cx) -> Result<Expr, Error>
Source§impl ReadConstructor for FunctionObject
impl ReadConstructor for FunctionObject
Auto Trait Implementations§
impl !RefUnwindSafe for FunctionObject
impl !UnwindSafe for FunctionObject
impl Freeze for FunctionObject
impl Send for FunctionObject
impl Sync for FunctionObject
impl Unpin for FunctionObject
impl UnsafeUnpin for FunctionObject
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more