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
impl Function
Sourcepub fn validate_input(&self, input: &InputValue) -> Option<bool>
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 schemaSome(false)if the input is invalidNonefor inline functions (no schema to validate against)
Sourcepub fn compile_tasks(
self,
input: &InputValue,
) -> Result<Vec<Option<CompiledTask>>, ExpressionError>
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:
Noneif the task was skippedSome(CompiledTask::One(...))for non-mapped tasksSome(CompiledTask::Many(...))for mapped tasks
Sourcepub fn compile_output_length(
self,
input: &InputValue,
) -> Result<Option<u64>, ExpressionError>
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 functionsOk(None)- For scalar functions or inline functionsErr(ExpressionError)- If the expression fails to compile
Sourcepub fn compile_input_split(
self,
input: &InputValue,
) -> Result<Option<Vec<InputValue>>, ExpressionError>
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 withinput_splitdefinedOk(None)- For scalar functions or functions withoutinput_splitErr(ExpressionError)- If the expression fails to compile
Sourcepub fn compile_input_merge(
self,
input: &InputValue,
) -> Result<Option<InputValue>, ExpressionError>
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 fromcompile_input_split)
§Returns
Ok(Some(Input))- The merged input for vector functions withinput_mergedefinedOk(None)- For scalar functions or functions withoutinput_mergeErr(ExpressionError)- If the expression fails to compile
Sourcepub fn description(&self) -> Option<&str>
pub fn description(&self) -> Option<&str>
Returns the function’s description, if available.
Sourcepub fn input_schema(&self) -> Option<&InputSchema>
pub fn input_schema(&self) -> Option<&InputSchema>
Returns the function’s input schema, if available.
Sourcepub fn tasks(&self) -> &[TaskExpression]
pub fn tasks(&self) -> &[TaskExpression]
Returns the function’s tasks.
Sourcepub fn output_length(&self) -> Option<&Expression>
pub fn output_length(&self) -> Option<&Expression>
Returns the function’s expected output length expression, if defined.
Sourcepub fn input_split(&self) -> Option<&Expression>
pub fn input_split(&self) -> Option<&Expression>
Returns the function’s input_split expression, if defined.
Sourcepub fn input_merge(&self) -> Option<&Expression>
pub fn input_merge(&self) -> Option<&Expression>
Returns the function’s input_merge expression, if defined.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Function
impl<'de> Deserialize<'de> for Function
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for Function
impl JsonSchema for Function
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreimpl StructuralPartialEq for Function
Auto Trait Implementations§
impl Freeze for Function
impl RefUnwindSafe for Function
impl Send for Function
impl Sync for Function
impl Unpin for Function
impl UnsafeUnpin for Function
impl UnwindSafe for Function
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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