Skip to main content

Function

Enum Function 

Source
pub enum Function {
    Remote(RemoteFunction),
    Inline(InlineFunction),
}
Expand description

A Function definition, either remote or inline.

Functions are composable scoring pipelines that transform structured input into scores. Each task has an output expression that transforms its raw result into a TaskOutputOwned. The function’s final output is the weighted average of all task outputs using profile weights.

Use compile_tasks to preview how task expressions resolve for given inputs.

Variants§

§

Remote(RemoteFunction)

A remote function with metadata (description, schema, etc.).

§

Inline(InlineFunction)

An inline function definition without metadata.

Implementations§

Source§

impl Function

Source

pub fn validate_input(&self, input: &InputValue) -> Option<bool>

Validates the input against the function’s input schema.

For remote functions, checks whether the provided input conforms to the function’s JSON Schema definition. For inline functions, returns None since they lack schema definitions.

§Returns
  • Some(true) if the input is valid against the schema
  • Some(false) if the input is invalid
  • None for inline functions (no schema to validate against)
Source

pub fn compile_tasks( self, input: &InputValue, ) -> Result<Vec<Option<CompiledTask>>, ExpressionError>

Compiles task expressions to show the final tasks for a given input.

Evaluates all expressions (JMESPath or Starlark) in the function’s tasks using the provided input data. Tasks with skip expressions that evaluate to true return None. Tasks with map fields produce multiple task instances.

§Returns

A vector where each element corresponds to a task definition:

  • None if the task was skipped
  • Some(CompiledTask::One(...)) for non-mapped tasks
  • Some(CompiledTask::Many(...)) for mapped tasks
Source

pub fn compile_output_length( self, input: &InputValue, ) -> Result<Option<u64>, ExpressionError>

Computes the expected output length for a vector function.

Evaluates the output_length expression to determine how many elements the output vector should contain. This is only applicable to remote vector functions which have an output_length field.

§Arguments
  • input - The function input used to compute the output length
§Returns
  • Ok(Some(u64)) - The expected output length for remote vector functions
  • Ok(None) - For scalar functions or inline functions
  • Err(ExpressionError) - If the expression fails to compile
Source

pub fn compile_input_split( self, input: &InputValue, ) -> Result<Option<Vec<InputValue>>, ExpressionError>

Compiles the input_split expression to split input into multiple sub-inputs.

Used by strategies like Swiss System that need to partition input into smaller pools. The expression transforms the original input into an array of inputs, where each element can be processed independently.

§Arguments
  • input - The original function input to split
§Returns
  • Ok(Some(Vec<Input>)) - The split inputs for vector functions with input_split defined
  • Ok(None) - For scalar functions or functions without input_split
  • Err(ExpressionError) - If the expression fails to compile
Source

pub fn compile_input_merge( self, input: &InputValue, ) -> Result<Option<InputValue>, ExpressionError>

Compiles the input_merge expression to merge multiple sub-inputs back into one.

Used by strategies like Swiss System to recombine a subset of split inputs into a single input for pool execution. The expression transforms an array of inputs (a subset from input_split) into a single merged input.

§Arguments
  • input - An array of inputs to merge (typically a subset from compile_input_split)
§Returns
  • Ok(Some(Input)) - The merged input for vector functions with input_merge defined
  • Ok(None) - For scalar functions or functions without input_merge
  • Err(ExpressionError) - If the expression fails to compile
Source

pub fn description(&self) -> Option<&str>

Returns the function’s description, if available.

Source

pub fn input_schema(&self) -> Option<&InputSchema>

Returns the function’s input schema, if available.

Source

pub fn tasks(&self) -> &[TaskExpression]

Returns the function’s tasks.

Source

pub fn output_length(&self) -> Option<&Expression>

Returns the function’s expected output length expression, if defined.

Source

pub fn input_split(&self) -> Option<&Expression>

Returns the function’s input_split expression, if defined.

Source

pub fn input_merge(&self) -> Option<&Expression>

Returns the function’s input_merge expression, if defined.

Trait Implementations§

Source§

impl Clone for Function

Source§

fn clone(&self) -> Function

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Function

Source§

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

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

impl<'de> Deserialize<'de> for Function

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for Function

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for Function

Source§

fn eq(&self, other: &Function) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Function

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Function

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

Source§

impl<T> ToAst for T

Source§

fn ast(self, begin: usize, end: usize) -> Spanned<Self>

Source§

impl<T> ToJmespath for T
where T: Serialize,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,