
# Objective - Contributes to #16877 ## Solution - Moved `hashbrown`, `foldhash`, and related types out of `bevy_utils` and into `bevy_platform_support` - Refactored the above to match the layout of these types in `std`. - Updated crates as required. ## Testing - CI --- ## Migration Guide - The following items were moved out of `bevy_utils` and into `bevy_platform_support::hash`: - `FixedState` - `DefaultHasher` - `RandomState` - `FixedHasher` - `Hashed` - `PassHash` - `PassHasher` - `NoOpHash` - The following items were moved out of `bevy_utils` and into `bevy_platform_support::collections`: - `HashMap` - `HashSet` - `bevy_utils::hashbrown` has been removed. Instead, import from `bevy_platform_support::collections` _or_ take a dependency on `hashbrown` directly. - `bevy_utils::Entry` has been removed. Instead, import from `bevy_platform_support::collections::hash_map` or `bevy_platform_support::collections::hash_set` as appropriate. - All of the above equally apply to `bevy::utils` and `bevy::platform_support`. ## Notes - I left `PreHashMap`, `PreHashMapExt`, and `TypeIdMap` in `bevy_utils` as they might be candidates for micro-crating. They can always be moved into `bevy_platform_support` at a later date if desired.
72 lines
2.7 KiB
Rust
72 lines
2.7 KiB
Rust
use crate::func::signature::ArgumentSignature;
|
|
use crate::func::{
|
|
args::{ArgCount, ArgError},
|
|
Return,
|
|
};
|
|
use alloc::borrow::Cow;
|
|
use bevy_platform_support::collections::HashSet;
|
|
use thiserror::Error;
|
|
|
|
/// An error that occurs when calling a [`DynamicFunction`] or [`DynamicFunctionMut`].
|
|
///
|
|
/// [`DynamicFunction`]: crate::func::DynamicFunction
|
|
/// [`DynamicFunctionMut`]: crate::func::DynamicFunctionMut
|
|
#[derive(Debug, Error, PartialEq)]
|
|
pub enum FunctionError {
|
|
/// An error occurred while converting an argument.
|
|
#[error(transparent)]
|
|
ArgError(#[from] ArgError),
|
|
/// The number of arguments provided does not match the expected number.
|
|
#[error("received {received} arguments but expected one of {expected:?}")]
|
|
ArgCountMismatch { expected: ArgCount, received: usize },
|
|
/// No overload was found for the given set of arguments.
|
|
#[error("no overload found for arguments with signature `{received:?}`, expected one of `{expected:?}`")]
|
|
NoOverload {
|
|
expected: HashSet<ArgumentSignature>,
|
|
received: ArgumentSignature,
|
|
},
|
|
}
|
|
|
|
/// The result of calling a [`DynamicFunction`] or [`DynamicFunctionMut`].
|
|
///
|
|
/// Returns `Ok(value)` if the function was called successfully,
|
|
/// where `value` is the [`Return`] value of the function.
|
|
///
|
|
/// [`DynamicFunction`]: crate::func::DynamicFunction
|
|
/// [`DynamicFunctionMut`]: crate::func::DynamicFunctionMut
|
|
pub type FunctionResult<'a> = Result<Return<'a>, FunctionError>;
|
|
|
|
/// An error that occurs when attempting to add a function overload.
|
|
#[derive(Debug, Error, PartialEq)]
|
|
pub enum FunctionOverloadError {
|
|
/// A [`SignatureInfo`] was expected, but none was found.
|
|
///
|
|
/// [`SignatureInfo`]: crate::func::info::SignatureInfo
|
|
#[error("expected at least one `SignatureInfo` but found none")]
|
|
MissingSignature,
|
|
/// An error that occurs when attempting to add a function overload with a duplicate signature.
|
|
#[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),
|
|
}
|
|
|
|
/// An error that occurs when registering a function into a [`FunctionRegistry`].
|
|
///
|
|
/// [`FunctionRegistry`]: crate::func::FunctionRegistry
|
|
#[derive(Debug, Error, PartialEq)]
|
|
pub enum FunctionRegistrationError {
|
|
/// A function with the given name has already been registered.
|
|
///
|
|
/// Contains the duplicate function name.
|
|
#[error("a function has already been registered with name {0:?}")]
|
|
DuplicateName(Cow<'static, str>),
|
|
/// The function is missing a name by which it can be registered.
|
|
#[error("function name is missing")]
|
|
MissingName,
|
|
}
|