use crate::func::signature::ArgumentSignature;1use crate::func::{2args::{ArgCount, ArgError},3Return,4};5use alloc::borrow::Cow;6use bevy_platform::collections::HashSet;7use thiserror::Error;89/// An error that occurs when calling a [`DynamicFunction`] or [`DynamicFunctionMut`].10///11/// [`DynamicFunction`]: crate::func::DynamicFunction12/// [`DynamicFunctionMut`]: crate::func::DynamicFunctionMut13#[derive(Debug, Error, PartialEq)]14pub enum FunctionError {15/// An error occurred while converting an argument.16#[error(transparent)]17ArgError(#[from] ArgError),18/// The number of arguments provided does not match the expected number.19#[error("received {received} arguments but expected one of {expected:?}")]20ArgCountMismatch {21/// Expected argument count. [`ArgCount`] for overloaded functions will contain multiple possible counts.22expected: ArgCount,23/// Number of arguments received.24received: usize,25},26/// No overload was found for the given set of arguments.27#[error("no overload found for arguments with signature `{received:?}`, expected one of `{expected:?}`")]28NoOverload {29/// The set of available argument signatures.30expected: HashSet<ArgumentSignature>,31/// The received argument signature.32received: ArgumentSignature,33},34}3536/// The result of calling a [`DynamicFunction`] or [`DynamicFunctionMut`].37///38/// Returns `Ok(value)` if the function was called successfully,39/// where `value` is the [`Return`] value of the function.40///41/// [`DynamicFunction`]: crate::func::DynamicFunction42/// [`DynamicFunctionMut`]: crate::func::DynamicFunctionMut43pub type FunctionResult<'a> = Result<Return<'a>, FunctionError>;4445/// An error that occurs when attempting to add a function overload.46#[derive(Debug, Error, PartialEq)]47pub enum FunctionOverloadError {48/// A [`SignatureInfo`] was expected, but none was found.49///50/// [`SignatureInfo`]: crate::func::info::SignatureInfo51#[error("expected at least one `SignatureInfo` but found none")]52MissingSignature,53/// An error that occurs when attempting to add a function overload with a duplicate signature.54#[error("could not add function overload: duplicate found for signature `{0:?}`")]55DuplicateSignature(ArgumentSignature),56/// An attempt was made to add an overload with more than [`ArgCount::MAX_COUNT`] arguments.57///58/// [`ArgCount::MAX_COUNT`]: crate::func::args::ArgCount59#[error(60"argument signature `{:?}` has too many arguments (max {})",610,62ArgCount::MAX_COUNT63)]64TooManyArguments(ArgumentSignature),65}6667/// An error that occurs when registering a function into a [`FunctionRegistry`].68///69/// [`FunctionRegistry`]: crate::func::FunctionRegistry70#[derive(Debug, Error, PartialEq)]71pub enum FunctionRegistrationError {72/// A function with the given name has already been registered.73///74/// Contains the duplicate function name.75#[error("a function has already been registered with name {0:?}")]76DuplicateName(Cow<'static, str>),77/// The function is missing a name by which it can be registered.78#[error("function name is missing")]79MissingName,80}818283