mirror of
https://github.com/bevyengine/bevy
synced 2024-11-14 08:58:04 +00:00
Remove thiserror
from bevy_reflect
(#15766)
# Objective - Contributes to #15460 ## Solution - Removed `thiserror` from `bevy_reflect`
This commit is contained in:
parent
46ad0b7513
commit
3cc1527e9e
11 changed files with 62 additions and 83 deletions
|
@ -38,7 +38,11 @@ bevy_ptr = { path = "../bevy_ptr", version = "0.15.0-dev" }
|
|||
erased-serde = "0.4"
|
||||
disqualified = "1.0"
|
||||
downcast-rs = "1.2"
|
||||
thiserror = "1.0"
|
||||
derive_more = { version = "1", default-features = false, features = [
|
||||
"error",
|
||||
"from",
|
||||
"display",
|
||||
] }
|
||||
serde = "1"
|
||||
smallvec = { version = "1.11", optional = true }
|
||||
assert_type_match = "0.1.1"
|
||||
|
|
|
@ -7,9 +7,10 @@ use crate::{
|
|||
};
|
||||
|
||||
use core::fmt::Formatter;
|
||||
use derive_more::derive::From;
|
||||
|
||||
/// A dynamic representation of an enum variant.
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, From)]
|
||||
pub enum DynamicVariant {
|
||||
#[default]
|
||||
Unit,
|
||||
|
@ -27,18 +28,6 @@ impl Clone for DynamicVariant {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<DynamicTuple> for DynamicVariant {
|
||||
fn from(dyn_tuple: DynamicTuple) -> Self {
|
||||
Self::Tuple(dyn_tuple)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DynamicStruct> for DynamicVariant {
|
||||
fn from(dyn_struct: DynamicStruct) -> Self {
|
||||
Self::Struct(dyn_struct)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<()> for DynamicVariant {
|
||||
fn from(_: ()) -> Self {
|
||||
Self::Unit
|
||||
|
|
|
@ -6,7 +6,7 @@ use bevy_utils::HashMap;
|
|||
use core::slice::Iter;
|
||||
|
||||
use alloc::sync::Arc;
|
||||
use thiserror::Error;
|
||||
use derive_more::derive::{Display, Error};
|
||||
|
||||
/// Describes the form of an enum variant.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
|
@ -40,12 +40,12 @@ pub enum VariantType {
|
|||
}
|
||||
|
||||
/// A [`VariantInfo`]-specific error.
|
||||
#[derive(Debug, Error)]
|
||||
#[derive(Debug, Error, Display)]
|
||||
pub enum VariantInfoError {
|
||||
/// Caused when a variant was expected to be of a certain [type], but was not.
|
||||
///
|
||||
/// [type]: VariantType
|
||||
#[error("variant type mismatch: expected {expected:?}, received {received:?}")]
|
||||
#[display("variant type mismatch: expected {expected:?}, received {received:?}")]
|
||||
TypeMismatch {
|
||||
expected: VariantType,
|
||||
received: VariantType,
|
||||
|
|
|
@ -1,23 +1,25 @@
|
|||
use alloc::borrow::Cow;
|
||||
|
||||
use thiserror::Error;
|
||||
use derive_more::derive::{Display, Error};
|
||||
|
||||
use crate::func::args::Ownership;
|
||||
|
||||
/// An error that occurs when converting an [argument].
|
||||
///
|
||||
/// [argument]: crate::func::args::Arg
|
||||
#[derive(Debug, Error, PartialEq)]
|
||||
#[derive(Debug, Error, Display, PartialEq)]
|
||||
pub enum ArgError {
|
||||
/// The argument is not the expected type.
|
||||
#[error("expected `{expected}` but received `{received}` (@ argument index {index})")]
|
||||
#[display("expected `{expected}` but received `{received}` (@ argument index {index})")]
|
||||
UnexpectedType {
|
||||
index: usize,
|
||||
expected: Cow<'static, str>,
|
||||
received: Cow<'static, str>,
|
||||
},
|
||||
/// The argument has the wrong ownership.
|
||||
#[error("expected {expected} value but received {received} value (@ argument index {index})")]
|
||||
#[display(
|
||||
"expected {expected} value but received {received} value (@ argument index {index})"
|
||||
)]
|
||||
InvalidOwnership {
|
||||
index: usize,
|
||||
expected: Ownership,
|
||||
|
@ -26,6 +28,6 @@ pub enum ArgError {
|
|||
/// Occurs when attempting to access an argument from an empty [`ArgList`].
|
||||
///
|
||||
/// [`ArgList`]: crate::func::args::ArgList
|
||||
#[error("expected an argument but received none")]
|
||||
#[display("expected an argument but received none")]
|
||||
EmptyArgList,
|
||||
}
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
use crate::func::{args::ArgError, Return};
|
||||
use alloc::borrow::Cow;
|
||||
use thiserror::Error;
|
||||
use derive_more::derive::{Display, Error, From};
|
||||
|
||||
/// An error that occurs when calling a [`DynamicFunction`] or [`DynamicFunctionMut`].
|
||||
///
|
||||
/// [`DynamicFunction`]: crate::func::DynamicFunction
|
||||
/// [`DynamicFunctionMut`]: crate::func::DynamicFunctionMut
|
||||
#[derive(Debug, Error, PartialEq)]
|
||||
#[derive(Debug, Error, Display, PartialEq, From)]
|
||||
pub enum FunctionError {
|
||||
/// An error occurred while converting an argument.
|
||||
#[error(transparent)]
|
||||
ArgError(#[from] ArgError),
|
||||
ArgError(ArgError),
|
||||
/// The number of arguments provided does not match the expected number.
|
||||
#[error("expected {expected} arguments but received {received}")]
|
||||
#[display("expected {expected} arguments but received {received}")]
|
||||
ArgCountMismatch { expected: usize, received: usize },
|
||||
}
|
||||
|
||||
|
@ -28,14 +27,15 @@ pub type FunctionResult<'a> = Result<Return<'a>, FunctionError>;
|
|||
/// An error that occurs when registering a function into a [`FunctionRegistry`].
|
||||
///
|
||||
/// [`FunctionRegistry`]: crate::func::FunctionRegistry
|
||||
#[derive(Debug, Error, PartialEq)]
|
||||
#[derive(Debug, Error, Display, 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:?}")]
|
||||
#[display("a function has already been registered with name {_0:?}")]
|
||||
#[error(ignore)]
|
||||
DuplicateName(Cow<'static, str>),
|
||||
/// The function is missing a name by which it can be registered.
|
||||
#[error("function name is missing")]
|
||||
#[display("function name is missing")]
|
||||
MissingName,
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ use crate::{Reflect, Type, TypePath};
|
|||
use alloc::borrow::Cow;
|
||||
use alloc::sync::Arc;
|
||||
use core::ops::Deref;
|
||||
use derive_more::derive::From;
|
||||
|
||||
/// The generic parameters of a type.
|
||||
///
|
||||
|
@ -63,7 +64,7 @@ impl Deref for Generics {
|
|||
}
|
||||
|
||||
/// An enum representing a generic parameter.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, From)]
|
||||
pub enum GenericInfo {
|
||||
/// A type parameter.
|
||||
///
|
||||
|
@ -100,18 +101,6 @@ impl GenericInfo {
|
|||
});
|
||||
}
|
||||
|
||||
impl From<TypeParamInfo> for GenericInfo {
|
||||
fn from(info: TypeParamInfo) -> Self {
|
||||
Self::Type(info)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ConstParamInfo> for GenericInfo {
|
||||
fn from(info: ConstParamInfo) -> Self {
|
||||
Self::Const(info)
|
||||
}
|
||||
}
|
||||
|
||||
/// Type information for a generic type parameter.
|
||||
///
|
||||
/// An example of a type parameter would be `T` in `struct Foo<T>`.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use thiserror::Error;
|
||||
use derive_more::derive::{Display, Error};
|
||||
|
||||
#[cfg(feature = "functions")]
|
||||
use crate::func::Function;
|
||||
|
@ -130,8 +130,8 @@ macro_rules! impl_reflect_kind_conversions {
|
|||
/// Caused when a type was expected to be of a certain [kind], but was not.
|
||||
///
|
||||
/// [kind]: ReflectKind
|
||||
#[derive(Debug, Error)]
|
||||
#[error("kind mismatch: expected {expected:?}, received {received:?}")]
|
||||
#[derive(Debug, Error, Display)]
|
||||
#[display("kind mismatch: expected {expected:?}, received {received:?}")]
|
||||
pub struct ReflectKindMismatchError {
|
||||
pub expected: ReflectKind,
|
||||
pub received: ReflectKind,
|
||||
|
|
|
@ -10,24 +10,23 @@ use parse::PathParser;
|
|||
|
||||
use crate::{PartialReflect, Reflect};
|
||||
use core::fmt;
|
||||
use thiserror::Error;
|
||||
use derive_more::derive::{Display, From};
|
||||
|
||||
type PathResult<'a, T> = Result<T, ReflectPathError<'a>>;
|
||||
|
||||
/// An error returned from a failed path string query.
|
||||
#[derive(Debug, PartialEq, Eq, Error)]
|
||||
#[derive(Debug, PartialEq, Eq, Display, From)]
|
||||
pub enum ReflectPathError<'a> {
|
||||
/// An error caused by trying to access a path that's not able to be accessed,
|
||||
/// see [`AccessError`] for details.
|
||||
#[error(transparent)]
|
||||
InvalidAccess(AccessError<'a>),
|
||||
|
||||
/// An error that occurs when a type cannot downcast to a given type.
|
||||
#[error("Can't downcast result of access to the given type")]
|
||||
#[display("Can't downcast result of access to the given type")]
|
||||
InvalidDowncast,
|
||||
|
||||
/// An error caused by an invalid path string that couldn't be parsed.
|
||||
#[error("Encountered an error at offset {offset} while parsing `{path}`: {error}")]
|
||||
#[display("Encountered an error at offset {offset} while parsing `{path}`: {error}")]
|
||||
ParseError {
|
||||
/// Position in `path`.
|
||||
offset: usize,
|
||||
|
@ -37,11 +36,8 @@ pub enum ReflectPathError<'a> {
|
|||
error: ParseError<'a>,
|
||||
},
|
||||
}
|
||||
impl<'a> From<AccessError<'a>> for ReflectPathError<'a> {
|
||||
fn from(value: AccessError<'a>) -> Self {
|
||||
Self::InvalidAccess(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> core::error::Error for ReflectPathError<'a> {}
|
||||
|
||||
/// Something that can be interpreted as a reflection path in [`GetPath`].
|
||||
pub trait ReflectPath<'a>: Sized {
|
||||
|
@ -355,7 +351,7 @@ impl From<Access<'static>> for OffsetAccess {
|
|||
/// ];
|
||||
/// let my_path = ParsedPath::from(path_elements);
|
||||
/// ```
|
||||
#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash)]
|
||||
#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash, From)]
|
||||
pub struct ParsedPath(
|
||||
/// This is a vector of pre-parsed [`OffsetAccess`]es.
|
||||
pub Vec<OffsetAccess>,
|
||||
|
@ -447,11 +443,6 @@ impl<'a> ReflectPath<'a> for &'a ParsedPath {
|
|||
Ok(root)
|
||||
}
|
||||
}
|
||||
impl From<Vec<OffsetAccess>> for ParsedPath {
|
||||
fn from(value: Vec<OffsetAccess>) -> Self {
|
||||
ParsedPath(value)
|
||||
}
|
||||
}
|
||||
impl<const N: usize> From<[OffsetAccess; N]> for ParsedPath {
|
||||
fn from(value: [OffsetAccess; N]) -> Self {
|
||||
ParsedPath(value.to_vec())
|
||||
|
|
|
@ -4,34 +4,38 @@ use core::{
|
|||
str::from_utf8_unchecked,
|
||||
};
|
||||
|
||||
use thiserror::Error;
|
||||
use derive_more::derive::{Display, Error, From};
|
||||
|
||||
use super::{Access, ReflectPathError};
|
||||
|
||||
/// An error that occurs when parsing reflect path strings.
|
||||
#[derive(Debug, PartialEq, Eq, Error)]
|
||||
#[error(transparent)]
|
||||
#[derive(Debug, PartialEq, Eq, Error, Display)]
|
||||
#[error(ignore)]
|
||||
pub struct ParseError<'a>(Error<'a>);
|
||||
|
||||
/// A parse error for a path string.
|
||||
#[derive(Debug, PartialEq, Eq, Error)]
|
||||
#[derive(Debug, PartialEq, Eq, Error, Display, From)]
|
||||
enum Error<'a> {
|
||||
#[error("expected an identifier, but reached end of path string")]
|
||||
#[display("expected an identifier, but reached end of path string")]
|
||||
NoIdent,
|
||||
|
||||
#[error("expected an identifier, got '{0}' instead")]
|
||||
#[display("expected an identifier, got '{_0}' instead")]
|
||||
#[error(ignore)]
|
||||
#[from(ignore)]
|
||||
ExpectedIdent(Token<'a>),
|
||||
|
||||
#[error("failed to parse index as integer")]
|
||||
InvalidIndex(#[from] ParseIntError),
|
||||
#[display("failed to parse index as integer")]
|
||||
InvalidIndex(ParseIntError),
|
||||
|
||||
#[error("a '[' wasn't closed, reached end of path string before finding a ']'")]
|
||||
#[display("a '[' wasn't closed, reached end of path string before finding a ']'")]
|
||||
Unclosed,
|
||||
|
||||
#[error("a '[' wasn't closed properly, got '{0}' instead")]
|
||||
#[display("a '[' wasn't closed properly, got '{_0}' instead")]
|
||||
#[error(ignore)]
|
||||
#[from(ignore)]
|
||||
BadClose(Token<'a>),
|
||||
|
||||
#[error("a ']' was found before an opening '['")]
|
||||
#[display("a ']' was found before an opening '['")]
|
||||
CloseBeforeOpen,
|
||||
}
|
||||
|
||||
|
|
|
@ -8,39 +8,39 @@ use core::{
|
|||
fmt::Debug,
|
||||
};
|
||||
|
||||
use thiserror::Error;
|
||||
use derive_more::derive::{Display, Error};
|
||||
|
||||
use crate::utility::NonGenericTypeInfoCell;
|
||||
|
||||
/// A enumeration of all error outcomes that might happen when running [`try_apply`](PartialReflect::try_apply).
|
||||
#[derive(Error, Debug)]
|
||||
#[derive(Error, Display, Debug)]
|
||||
pub enum ApplyError {
|
||||
#[error("attempted to apply `{from_kind}` to `{to_kind}`")]
|
||||
#[display("attempted to apply `{from_kind}` to `{to_kind}`")]
|
||||
/// Attempted to apply the wrong [kind](ReflectKind) to a type, e.g. a struct to a enum.
|
||||
MismatchedKinds {
|
||||
from_kind: ReflectKind,
|
||||
to_kind: ReflectKind,
|
||||
},
|
||||
|
||||
#[error("enum variant `{variant_name}` doesn't have a field named `{field_name}`")]
|
||||
#[display("enum variant `{variant_name}` doesn't have a field named `{field_name}`")]
|
||||
/// Enum variant that we tried to apply to was missing a field.
|
||||
MissingEnumField {
|
||||
variant_name: Box<str>,
|
||||
field_name: Box<str>,
|
||||
},
|
||||
|
||||
#[error("`{from_type}` is not `{to_type}`")]
|
||||
#[display("`{from_type}` is not `{to_type}`")]
|
||||
/// Tried to apply incompatible types.
|
||||
MismatchedTypes {
|
||||
from_type: Box<str>,
|
||||
to_type: Box<str>,
|
||||
},
|
||||
|
||||
#[error("attempted to apply type with {from_size} size to a type with {to_size} size")]
|
||||
#[display("attempted to apply type with {from_size} size to a type with {to_size} size")]
|
||||
/// Attempted to apply to types with mismatched sizez, e.g. a [u8; 4] to [u8; 3].
|
||||
DifferentSize { from_size: usize, to_size: usize },
|
||||
|
||||
#[error("variant with name `{variant_name}` does not exist on enum `{enum_name}`")]
|
||||
#[display("variant with name `{variant_name}` does not exist on enum `{enum_name}`")]
|
||||
/// The enum we tried to apply to didn't contain a variant with the give name.
|
||||
UnknownVariant {
|
||||
enum_name: Box<str>,
|
||||
|
|
|
@ -8,7 +8,7 @@ use core::{
|
|||
fmt::{Debug, Formatter},
|
||||
hash::Hash,
|
||||
};
|
||||
use thiserror::Error;
|
||||
use derive_more::derive::{Display, Error};
|
||||
|
||||
/// A static accessor to compile-time type information.
|
||||
///
|
||||
|
@ -163,12 +163,12 @@ impl<T: Typed> DynamicTyped for T {
|
|||
}
|
||||
|
||||
/// A [`TypeInfo`]-specific error.
|
||||
#[derive(Debug, Error)]
|
||||
#[derive(Debug, Error, Display)]
|
||||
pub enum TypeInfoError {
|
||||
/// Caused when a type was expected to be of a certain [kind], but was not.
|
||||
///
|
||||
/// [kind]: ReflectKind
|
||||
#[error("kind mismatch: expected {expected:?}, received {received:?}")]
|
||||
#[display("kind mismatch: expected {expected:?}, received {received:?}")]
|
||||
KindMismatch {
|
||||
expected: ReflectKind,
|
||||
received: ReflectKind,
|
||||
|
|
Loading…
Reference in a new issue