bevy_ecs/identifier/error.rs
1//! Error types for [`super::Identifier`] conversions. An ID can be converted
2//! to various kinds, but these can fail if they are not valid forms of those
3//! kinds. The error type in this module encapsulates the various failure modes.
4use core::fmt;
5
6/// An Error type for [`super::Identifier`], mostly for providing error
7/// handling for conversions of an ID to a type abstracting over the ID bits.
8#[derive(Debug, PartialEq, Eq, Clone, Copy)]
9#[non_exhaustive]
10pub enum IdentifierError {
11 /// A given ID has an invalid value for initializing to a [`crate::identifier::Identifier`].
12 InvalidIdentifier,
13 /// A given ID has an invalid configuration of bits for converting to an [`crate::entity::Entity`].
14 InvalidEntityId(u64),
15}
16
17impl fmt::Display for IdentifierError {
18 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19 match self {
20 Self::InvalidIdentifier => write!(
21 f,
22 "The given id contains a zero value high component, which is invalid"
23 ),
24 Self::InvalidEntityId(_) => write!(f, "The given id is not a valid entity."),
25 }
26 }
27}
28
29impl core::error::Error for IdentifierError {}