pub trait TypePath: 'static {
// Required methods
fn type_path() -> &'static str;
fn short_type_path() -> &'static str;
// Provided methods
fn type_ident() -> Option<&'static str> { ... }
fn crate_name() -> Option<&'static str> { ... }
fn module_path() -> Option<&'static str> { ... }
}
Expand description
A static accessor to type paths and names.
The engine uses this trait over std::any::type_name
for stability and flexibility.
This trait is automatically implemented by the #[derive(Reflect)]
macro
and allows type path information to be processed without an instance of that type.
Implementors may have difficulty in generating references with static lifetimes. Luckily, this crate comes with some utility structs, to make generating these statics much simpler.
§Stability
Certain parts of the engine, e.g. (de)serialization, rely on type paths as identifiers for matching dynamic values to concrete types.
Using std::any::type_name
, a scene containing my_crate::foo::MyComponent
would break,
failing to deserialize if the component was moved from the foo
module to the bar
module,
becoming my_crate::bar::MyComponent
.
This trait, through attributes when deriving itself or Reflect
, can ensure breaking changes are avoidable.
The only external factor we rely on for stability when deriving is the module_path!
macro,
only if the derive does not provide a #[type_path = "..."]
attribute.
§Anonymity
Some methods on this trait return Option<&'static str>
over &'static str
because not all types define all parts of a type path, for example the array type [T; N]
.
Such types are ‘anonymous’ in that they have only a defined type_path
and short_type_path
and the methods crate_name
, module_path
and type_ident
all return None
.
Primitives are treated like anonymous types, except they also have a defined type_ident
.
§Example
use bevy_reflect::TypePath;
// This type path will not change with compiler versions or recompiles,
// although it will not be the same if the definition is moved.
#[derive(TypePath)]
struct NonStableTypePath;
// This type path will never change, even if the definition is moved.
#[derive(TypePath)]
#[type_path = "my_crate::foo"]
struct StableTypePath;
// Type paths can have any number of path segments.
#[derive(TypePath)]
#[type_path = "my_crate::foo::bar::baz"]
struct DeeplyNestedStableTypePath;
// Including just a crate name!
#[derive(TypePath)]
#[type_path = "my_crate"]
struct ShallowStableTypePath;
// We can also rename the identifier/name of types.
#[derive(TypePath)]
#[type_path = "my_crate::foo"]
#[type_name = "RenamedStableTypePath"]
struct NamedStableTypePath;
// Generics are also supported.
#[derive(TypePath)]
#[type_path = "my_crate::foo"]
struct StableGenericTypePath<T, const N: usize>([T; N]);
Required Methods§
sourcefn type_path() -> &'static str
fn type_path() -> &'static str
Returns the fully qualified path of the underlying type.
Generic parameter types are also fully expanded.
For Option<Vec<usize>>
, this is "std::option::Option<std::vec::Vec<usize>>"
.
sourcefn short_type_path() -> &'static str
fn short_type_path() -> &'static str
Returns a short, pretty-print enabled path to the type.
Generic parameter types are also shortened.
For Option<Vec<usize>>
, this is "Option<Vec<usize>>"
.
Provided Methods§
sourcefn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
sourcefn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
Object Safety§
Implementations on Foreign Types§
source§impl TypePath for BuildHasherDefault<AHasher>
impl TypePath for BuildHasherDefault<AHasher>
source§impl TypePath for AtomicBool
impl TypePath for AtomicBool
source§impl TypePath for AtomicIsize
impl TypePath for AtomicIsize
source§impl TypePath for AtomicUsize
impl TypePath for AtomicUsize
source§impl TypePath for RandomState
impl TypePath for RandomState
source§impl<P1, P2, P0> TypePath for (P1, P2, P0)
impl<P1, P2, P0> TypePath for (P1, P2, P0)
source§impl<P1, P2, P3, P0> TypePath for (P1, P2, P3, P0)
impl<P1, P2, P3, P0> TypePath for (P1, P2, P3, P0)
source§impl<P1, P2, P3, P4, P0> TypePath for (P1, P2, P3, P4, P0)
impl<P1, P2, P3, P4, P0> TypePath for (P1, P2, P3, P4, P0)
source§impl<P1, P2, P3, P4, P5, P0> TypePath for (P1, P2, P3, P4, P5, P0)
impl<P1, P2, P3, P4, P5, P0> TypePath for (P1, P2, P3, P4, P5, P0)
source§impl<P1, P2, P3, P4, P5, P6, P0> TypePath for (P1, P2, P3, P4, P5, P6, P0)
impl<P1, P2, P3, P4, P5, P6, P0> TypePath for (P1, P2, P3, P4, P5, P6, P0)
source§impl<P1, P2, P3, P4, P5, P6, P7, P0> TypePath for (P1, P2, P3, P4, P5, P6, P7, P0)
impl<P1, P2, P3, P4, P5, P6, P7, P0> TypePath for (P1, P2, P3, P4, P5, P6, P7, P0)
source§impl<P1, P2, P3, P4, P5, P6, P7, P8, P0> TypePath for (P1, P2, P3, P4, P5, P6, P7, P8, P0)
impl<P1, P2, P3, P4, P5, P6, P7, P8, P0> TypePath for (P1, P2, P3, P4, P5, P6, P7, P8, P0)
source§impl<P1, P2, P3, P4, P5, P6, P7, P8, P9, P0> TypePath for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P0)
impl<P1, P2, P3, P4, P5, P6, P7, P8, P9, P0> TypePath for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P0)
source§impl<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P0> TypePath for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P0)
impl<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P0> TypePath for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P0)
source§impl<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P0> TypePath for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P0)
impl<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P0> TypePath for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P0)
source§impl<T> TypePath for &'static T
impl<T> TypePath for &'static T
source§impl<T> TypePath for &'static mut T
impl<T> TypePath for &'static mut T
source§impl<T> TypePath for BinaryHeap<T>
impl<T> TypePath for BinaryHeap<T>
source§impl<T> TypePath for Saturating<T>
impl<T> TypePath for Saturating<T>
source§impl<T> TypePath for RangeInclusive<T>
impl<T> TypePath for RangeInclusive<T>
source§impl<T> TypePath for RangeToInclusive<T>
impl<T> TypePath for RangeToInclusive<T>
Implementors§
impl TypePath for HierarchyEvent
impl TypePath for ButtonState
impl TypePath for GamepadConnection
impl TypePath for GamepadEvent
impl TypePath for GamepadInput
impl TypePath for GamepadRumbleRequest
impl TypePath for RawGamepadEvent
impl TypePath for Key
impl TypePath for NativeKey
impl TypePath for NativeKeyCode
impl TypePath for MouseScrollUnit
impl TypePath for GamepadAxis
impl TypePath for GamepadButton
impl TypePath for KeyCode
impl TypePath for MouseButton
impl TypePath for ForceTouch
impl TypePath for TouchPhase
impl TypePath for CompassOctant
impl TypePath for CompassQuadrant
impl TypePath for EulerRot
impl TypePath for EaseFunction
impl TypePath for TimerMode
impl TypePath for Name
impl TypePath for ComponentId
impl TypePath for ComponentTicks
impl TypePath for Tick
impl TypePath for EntityHash
impl TypePath for Identifier
impl TypePath for Entity
impl TypePath for OnAdd
impl TypePath for OnInsert
impl TypePath for OnRemove
impl TypePath for OnReplace
impl TypePath for RemovedComponentEntity
impl TypePath for SystemIdMarker
impl TypePath for Children
impl TypePath for Parent
impl TypePath for AxisSettings
impl TypePath for ButtonAxisSettings
impl TypePath for ButtonSettings
impl TypePath for GamepadAxisChangedEvent
impl TypePath for GamepadButtonChangedEvent
impl TypePath for GamepadButtonStateChangedEvent
impl TypePath for GamepadConnectionEvent
impl TypePath for GamepadRumbleIntensity
impl TypePath for RawGamepadAxisChangedEvent
impl TypePath for RawGamepadButtonChangedEvent
impl TypePath for DoubleTapGesture
impl TypePath for PanGesture
impl TypePath for PinchGesture
impl TypePath for RotationGesture
impl TypePath for KeyboardFocusLost
impl TypePath for KeyboardInput
impl TypePath for AccumulatedMouseMotion
impl TypePath for AccumulatedMouseScroll
impl TypePath for MouseButtonInput
impl TypePath for MouseMotion
impl TypePath for MouseWheel
impl TypePath for Gamepad
impl TypePath for GamepadSettings
impl TypePath for TouchInput
impl TypePath for BVec2
impl TypePath for BVec3
impl TypePath for BVec4
impl TypePath for Aabb2d
impl TypePath for Aabb3d
impl TypePath for AabbCast2d
impl TypePath for AabbCast3d
impl TypePath for BoundingCircle
impl TypePath for BoundingCircleCast
impl TypePath for BoundingSphere
impl TypePath for BoundingSphereCast
impl TypePath for RayCast2d
impl TypePath for RayCast3d
impl TypePath for Affine2
impl TypePath for Affine3A
impl TypePath for Mat2
impl TypePath for Mat3
impl TypePath for Mat3A
impl TypePath for Mat4
impl TypePath for Quat
impl TypePath for Vec2
impl TypePath for Vec3
impl TypePath for Vec3A
impl TypePath for Vec4
impl TypePath for IVec2
impl TypePath for IVec3
impl TypePath for IVec4
impl TypePath for Annulus
impl TypePath for Arc2d
impl TypePath for Capsule2d
impl TypePath for Capsule3d
impl TypePath for Circle
impl TypePath for CircularSector
impl TypePath for CircularSegment
impl TypePath for Cone
impl TypePath for ConicalFrustum
impl TypePath for Cuboid
impl TypePath for Cylinder
impl TypePath for Ellipse
impl TypePath for InfinitePlane3d
impl TypePath for Interval
impl TypePath for Line2d
impl TypePath for Line3d
impl TypePath for Plane2d
impl TypePath for Plane3d
impl TypePath for Rectangle
impl TypePath for RegularPolygon
impl TypePath for Rhombus
impl TypePath for Segment2d
impl TypePath for Segment3d
impl TypePath for Sphere
impl TypePath for Tetrahedron
impl TypePath for Torus
impl TypePath for Triangle2d
impl TypePath for Triangle3d
impl TypePath for Affine3
impl TypePath for AspectRatio
impl TypePath for BVec3A
impl TypePath for BVec4A
impl TypePath for DAffine2
impl TypePath for DAffine3
impl TypePath for DMat2
impl TypePath for DMat3
impl TypePath for DMat4
impl TypePath for DQuat
impl TypePath for DVec2
impl TypePath for DVec3
impl TypePath for DVec4
impl TypePath for Dir2
impl TypePath for Dir3
impl TypePath for Dir3A
impl TypePath for FloatOrd
impl TypePath for I64Vec2
impl TypePath for I64Vec3
impl TypePath for I64Vec4
impl TypePath for IRect
impl TypePath for Isometry2d
impl TypePath for Isometry3d
impl TypePath for Ray2d
impl TypePath for Ray3d
impl TypePath for Rect
impl TypePath for Rot2
impl TypePath for U64Vec2
impl TypePath for U64Vec3
impl TypePath for U64Vec4
impl TypePath for URect
impl TypePath for UVec2
impl TypePath for UVec3
impl TypePath for UVec4
impl TypePath for Fixed
impl TypePath for Real
impl TypePath for Stopwatch
impl TypePath for Timer
impl TypePath for Virtual
impl TypePath for GlobalTransform
impl TypePath for Transform
impl TypePath for Duration
impl TypePath for FixedState
impl TypePath for Instant
impl TypePath for NoOpHash
impl TypePath for DynamicArray
impl TypePath for DynamicEnum
impl TypePath for DynamicList
impl TypePath for DynamicMap
impl TypePath for DynamicSet
impl TypePath for DynamicStruct
impl TypePath for DynamicTuple
impl TypePath for DynamicTupleStruct
impl TypePath for dyn PartialReflect
impl TypePath for dyn Reflect
impl<E> TypePath for EventId<E>
impl<E> TypePath for Events<E>
impl<K, V, S> TypePath for bevy::utils::hashbrown::HashMap<K, V, S>
impl<P> TypePath for LinearSpline<P>
impl<P> TypePath for CubicBSpline<P>
impl<P> TypePath for CubicBezier<P>
impl<P> TypePath for CubicCardinalSpline<P>
impl<P> TypePath for CubicCurve<P>
impl<P> TypePath for CubicHermite<P>
impl<P> TypePath for CubicNurbs<P>
impl<P> TypePath for CubicSegment<P>
impl<P> TypePath for RationalCurve<P>
impl<P> TypePath for RationalSegment<P>
impl<S, T, C, D> TypePath for ZipCurve<S, T, C, D>
impl<S, T, C, F> TypePath for MapCurve<S, T, C, F>
Note: This is not a fully stable implementation of TypePath
due to usage of type_name
for function members.
impl<T> TypePath for InterpolationDatum<T>
impl<T> TypePath for Axis<T>
impl<T> TypePath for ButtonInput<T>
impl<T> TypePath for ConstantCurve<T>
impl<T> TypePath for EasingCurve<T>
impl<T> TypePath for SampleAutoCurve<T>
impl<T> TypePath for UnevenSampleAutoCurve<T>
impl<T> TypePath for ChunkedUnevenCore<T>
impl<T> TypePath for EvenCore<T>
impl<T> TypePath for UnevenCore<T>
impl<T> TypePath for Time<T>
impl<T, C> TypePath for ForeverCurve<T, C>
impl<T, C> TypePath for GraphCurve<T, C>
impl<T, C> TypePath for LinearReparamCurve<T, C>
impl<T, C> TypePath for PingPongCurve<T, C>
impl<T, C> TypePath for RepeatCurve<T, C>
impl<T, C> TypePath for ReverseCurve<T, C>
impl<T, C, D> TypePath for ChainCurve<T, C, D>
impl<T, C, D> TypePath for ContinuationCurve<T, C, D>
impl<T, C, D> TypePath for CurveReparamCurve<T, C, D>
impl<T, C, F> TypePath for ReparamCurve<T, C, F>
Note: This is not a fully stable implementation of TypePath
due to usage of type_name
for function members.
impl<T, F> TypePath for FunctionCurve<T, F>where
T: TypePath,
F: 'static,
Note: This is not a fully stable implementation of TypePath
due to usage of type_name
for function members.
impl<T, I> TypePath for SampleCurve<T, I>where
T: TypePath,
I: 'static,
Note: This is not a fully stable implementation of TypePath
due to usage of type_name
for function members.
impl<T, I> TypePath for UnevenSampleCurve<T, I>where
T: TypePath,
I: 'static,
Note: This is not a fully stable implementation of TypePath
due to usage of type_name
for function members.