Trait yarnspinner::core::YarnFn
source · pub trait YarnFn<Marker>: Clone + Send + Sync {
type Out: IntoYarnValueFromNonYarnValue + 'static;
// Required method
fn parameter_types(&self) -> Vec<TypeId>;
// Provided method
fn return_type(&self) -> TypeId { ... }
}
Expand description
A function that can be registered into and called from Yarn. It must have the following properties:
- It is allowed to have zero or more parameters
- Each parameter must be a
YarnFnParam
, which means of the following types or a reference to them: - It must return a value.
- Its return type must be one of the following types:
§Examples
fn give_summary(name: &str, age: usize, is_cool: bool) -> String {
format!("{name} is {age} years old and is {} cool", if is_cool { "very" } else { "not" })
}
Which may be called from Yarn as follows:
<<set $name to "Bob">>
<<set $age to 42>>
<<set $is_cool to true>>
Narrator: {give_summary($name, $age, $is_cool)}
Required Associated Types§
sourcetype Out: IntoYarnValueFromNonYarnValue + 'static
type Out: IntoYarnValueFromNonYarnValue + 'static
The type of the value returned by this function. See YarnFn
for more information about what is allowed.
Required Methods§
sourcefn parameter_types(&self) -> Vec<TypeId>
fn parameter_types(&self) -> Vec<TypeId>
The TypeId
s of the parameters of this function.
Provided Methods§
sourcefn return_type(&self) -> TypeId
fn return_type(&self) -> TypeId
The TypeId
of the return type of this function.
Object Safety§
This trait is not object safe.