use crate::func::signature::ArgumentSignature;
use crate::func::{
args::{ArgCount, ArgError},
Return,
};
use alloc::borrow::Cow;
use bevy_platform::collections::HashSet;
use thiserror::Error;
#[derive(Debug, Error, PartialEq)]
pub enum FunctionError {
#[error(transparent)]
ArgError(#[from] ArgError),
#[error("received {received} arguments but expected one of {expected:?}")]
ArgCountMismatch {
expected: ArgCount,
received: usize,
},
#[error("no overload found for arguments with signature `{received:?}`, expected one of `{expected:?}`")]
NoOverload {
expected: HashSet<ArgumentSignature>,
received: ArgumentSignature,
},
}
pub type FunctionResult<'a> = Result<Return<'a>, FunctionError>;
#[derive(Debug, Error, PartialEq)]
pub enum FunctionOverloadError {
#[error("expected at least one `SignatureInfo` but found none")]
MissingSignature,
#[error("could not add function overload: duplicate found for signature `{0:?}`")]
DuplicateSignature(ArgumentSignature),
#[error(
"argument signature `{:?}` has too many arguments (max {})",
0,
ArgCount::MAX_COUNT
)]
TooManyArguments(ArgumentSignature),
}
#[derive(Debug, Error, PartialEq)]
pub enum FunctionRegistrationError {
#[error("a function has already been registered with name {0:?}")]
DuplicateName(Cow<'static, str>),
#[error("function name is missing")]
MissingName,
}