Trait Struct

Source
pub trait Struct: PartialReflect {
    // Required methods
    fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>;
    fn field_mut(
        &mut self,
        name: &str,
    ) -> Option<&mut (dyn PartialReflect + 'static)>;
    fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>;
    fn field_at_mut(
        &mut self,
        index: usize,
    ) -> Option<&mut (dyn PartialReflect + 'static)>;
    fn name_at(&self, index: usize) -> Option<&str>;
    fn field_len(&self) -> usize;
    fn iter_fields(&self) -> FieldIter<'_> ;

    // Provided methods
    fn to_dynamic_struct(&self) -> DynamicStruct { ... }
    fn get_represented_struct_info(&self) -> Option<&'static StructInfo> { ... }
}
Expand description

A trait used to power struct-like operations via reflection.

This trait uses the Reflect trait to allow implementors to have their fields be dynamically addressed by both name and index.

When using #[derive(Reflect)] on a standard struct, this trait will be automatically implemented. This goes for unit structs as well.

§Example

use bevy_reflect::{PartialReflect, Reflect, Struct};

#[derive(Reflect)]
struct Foo {
    bar: u32,
}

let foo = Foo { bar: 123 };

assert_eq!(foo.field_len(), 1);
assert_eq!(foo.name_at(0), Some("bar"));

let field: &dyn PartialReflect = foo.field("bar").unwrap();
assert_eq!(field.try_downcast_ref::<u32>(), Some(&123));

Required Methods§

Source

fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field named name as a &dyn PartialReflect.

Source

fn field_mut( &mut self, name: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>

Returns a mutable reference to the value of the field named name as a &mut dyn PartialReflect.

Source

fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field with index index as a &dyn PartialReflect.

Source

fn field_at_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Returns a mutable reference to the value of the field with index index as a &mut dyn PartialReflect.

Source

fn name_at(&self, index: usize) -> Option<&str>

Returns the name of the field with index index.

Source

fn field_len(&self) -> usize

Returns the number of fields in the struct.

Source

fn iter_fields(&self) -> FieldIter<'_>

Returns an iterator over the values of the reflectable fields for this struct.

Provided Methods§

Source

fn to_dynamic_struct(&self) -> DynamicStruct

Creates a new DynamicStruct from this struct.

Source

fn get_represented_struct_info(&self) -> Option<&'static StructInfo>

Will return None if TypeInfo is not available.

Trait Implementations§

Source§

impl GetField for dyn Struct

Source§

fn get_field<T>(&self, name: &str) -> Option<&T>
where T: Reflect,

Returns a reference to the value of the field named name, downcast to T.
Source§

fn get_field_mut<T>(&mut self, name: &str) -> Option<&mut T>
where T: Reflect,

Returns a mutable reference to the value of the field named name, downcast to T.

Implementors§

Source§

impl Struct for ComponentTicks

Source§

impl Struct for Tick

Source§

impl Struct for EntityHash

Source§

impl Struct for DefaultQueryFilters

Source§

impl Struct for Disabled

Source§

impl Struct for Internal

Source§

impl Struct for AxisSettings

Source§

impl Struct for ButtonAxisSettings

Source§

impl Struct for ButtonSettings

Source§

impl Struct for GamepadAxisChangedEvent

Source§

impl Struct for GamepadButtonChangedEvent

Source§

impl Struct for GamepadButtonStateChangedEvent

Source§

impl Struct for GamepadConnectionEvent

Source§

impl Struct for GamepadRumbleIntensity

Source§

impl Struct for RawGamepadAxisChangedEvent

Source§

impl Struct for RawGamepadButtonChangedEvent

Source§

impl Struct for DoubleTapGesture

Source§

impl Struct for KeyboardFocusLost

Source§

impl Struct for KeyboardInput

Source§

impl Struct for AccumulatedMouseMotion

Source§

impl Struct for AccumulatedMouseScroll

Source§

impl Struct for MouseButtonInput

Source§

impl Struct for MouseMotion

Source§

impl Struct for MouseWheel

Source§

impl Struct for Aabb2d

Source§

impl Struct for Aabb3d

Source§

impl Struct for AabbCast2d

Source§

impl Struct for AabbCast3d

Source§

impl Struct for BoundingCircle

Source§

impl Struct for BoundingCircleCast

Source§

impl Struct for BoundingSphere

Source§

impl Struct for BoundingSphereCast

Source§

impl Struct for RayCast2d

Source§

impl Struct for RayCast3d

Source§

impl Struct for Affine2

Source§

impl Struct for Affine3

Source§

impl Struct for Affine3A

Source§

impl Struct for DAffine2

Source§

impl Struct for DAffine3

Source§

impl Struct for DMat2

Source§

impl Struct for DMat3

Source§

impl Struct for DMat4

Source§

impl Struct for DQuat

Source§

impl Struct for DVec2

Source§

impl Struct for DVec3

Source§

impl Struct for DVec4

Source§

impl Struct for I8Vec2

Source§

impl Struct for I8Vec3

Source§

impl Struct for I8Vec4

Source§

impl Struct for I16Vec2

Source§

impl Struct for I16Vec3

Source§

impl Struct for I16Vec4

Source§

impl Struct for I64Vec2

Source§

impl Struct for I64Vec3

Source§

impl Struct for I64Vec4

Source§

impl Struct for U8Vec2

Source§

impl Struct for U8Vec3

Source§

impl Struct for U8Vec4

Source§

impl Struct for U16Vec2

Source§

impl Struct for U16Vec3

Source§

impl Struct for U16Vec4

Source§

impl Struct for U64Vec2

Source§

impl Struct for U64Vec3

Source§

impl Struct for U64Vec4

Source§

impl Struct for Add

Source§

impl Struct for Annulus

Source§

impl Struct for Arc2d

Source§

impl Struct for BVec2

Source§

impl Struct for BVec3

Source§

impl Struct for BVec4

Source§

impl Struct for Capsule2d

Source§

impl Struct for Capsule3d

Source§

impl Struct for Circle

Source§

impl Struct for CircularSector

Source§

impl Struct for CircularSegment

Source§

impl Struct for Cone

Source§

impl Struct for ConicalFrustum

Source§

impl Struct for ConvexPolygon

Source§

impl Struct for Cuboid

Source§

impl Struct for Cylinder

Source§

impl Struct for Despawn

Source§

impl Struct for Ellipse

Source§

impl Struct for Fixed

Source§

impl Struct for Gamepad

Source§

impl Struct for GamepadSettings

Source§

impl Struct for IRect

Source§

impl Struct for IVec2

Source§

impl Struct for IVec3

Source§

impl Struct for IVec4

Source§

impl Struct for InfinitePlane3d

Source§

impl Struct for Insert

Source§

impl Struct for Isometry2d

Source§

impl Struct for Isometry3d

Source§

impl Struct for Line2d

Source§

impl Struct for Line3d

Source§

impl Struct for Mat2

Source§

impl Struct for Mat3

Source§

impl Struct for Mat3A

Source§

impl Struct for Mat4

Source§

impl Struct for Name

Source§

impl Struct for Plane2d

Source§

impl Struct for Plane3d

Source§

impl Struct for Polygon

Source§

impl Struct for Polyline2d

Source§

impl Struct for Polyline3d

Source§

impl Struct for Quat

Source§

impl Struct for Ray2d

Source§

impl Struct for Ray3d

Source§

impl Struct for Real

Source§

impl Struct for Rect

Source§

impl Struct for Rectangle

Source§

impl Struct for RegularPolygon

Source§

impl Struct for Remove

Source§

impl Struct for Replace

Source§

impl Struct for Rhombus

Source§

impl Struct for Rot2

Source§

impl Struct for Segment2d

Source§

impl Struct for Segment3d

Source§

impl Struct for Sphere

Source§

impl Struct for Tetrahedron

Source§

impl Struct for Timer

Source§

impl Struct for Torus

Source§

impl Struct for TouchInput

Source§

impl Struct for Transform

Source§

impl Struct for TransformTreeChanged

Source§

impl Struct for Triangle2d

Source§

impl Struct for Triangle3d

Source§

impl Struct for URect

Source§

impl Struct for UVec2

Source§

impl Struct for UVec3

Source§

impl Struct for UVec4

Source§

impl Struct for Vec2

Source§

impl Struct for Vec3

Source§

impl Struct for Vec3A

Source§

impl Struct for Vec4

Source§

impl Struct for Virtual

Source§

impl Struct for Stopwatch

Source§

impl Struct for DynamicStruct

Source§

impl<E> Struct for Messages<E>
where E: Message + TypePath, Messages<E>: Any + Send + Sync, MessageSequence<E>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<M> Struct for MessageId<M>
where M: Message + TypePath, MessageId<M>: Any + Send + Sync,

Source§

impl<P> Struct for LinearSpline<P>
where P: VectorSpace + TypePath, LinearSpline<P>: Any + Send + Sync, Vec<P>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<P> Struct for CubicBSpline<P>
where P: VectorSpace + TypePath, CubicBSpline<P>: Any + Send + Sync, Vec<P>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<P> Struct for CubicBezier<P>
where P: VectorSpace + TypePath, CubicBezier<P>: Any + Send + Sync, Vec<[P; 4]>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<P> Struct for CubicCardinalSpline<P>
where P: VectorSpace + TypePath, CubicCardinalSpline<P>: Any + Send + Sync, Vec<P>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<P> Struct for CubicCurve<P>
where P: VectorSpace + TypePath, CubicCurve<P>: Any + Send + Sync, Vec<CubicSegment<P>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<P> Struct for CubicHermite<P>
where P: VectorSpace + TypePath, CubicHermite<P>: Any + Send + Sync, Vec<(P, P)>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<P> Struct for CubicNurbs<P>
where P: VectorSpace + TypePath, CubicNurbs<P>: Any + Send + Sync, Vec<P>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<P> Struct for CubicSegment<P>
where P: VectorSpace + TypePath, CubicSegment<P>: Any + Send + Sync, [P; 4]: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<P> Struct for RationalCurve<P>
where P: VectorSpace + TypePath, RationalCurve<P>: Any + Send + Sync, Vec<RationalSegment<P>>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<P> Struct for RationalSegment<P>
where P: VectorSpace + TypePath, RationalSegment<P>: Any + Send + Sync, [P; 4]: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<T> Struct for MaybeLocation<T>
where MaybeLocation<T>: Any + Send + Sync, T: TypePath + ?Sized,

Source§

impl<T> Struct for WithDerivative<T>
where WithDerivative<T>: Any + Send + Sync, T: HasTangent + TypePath + FromReflect + MaybeTyped + RegisterForReflection, <T as HasTangent>::Tangent: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<T> Struct for WithTwoDerivatives<T>
where WithTwoDerivatives<T>: Any + Send + Sync, T: HasTangent + TypePath + FromReflect + MaybeTyped + RegisterForReflection, <T as HasTangent>::Tangent: FromReflect + TypePath + MaybeTyped + RegisterForReflection, <<T as HasTangent>::Tangent as HasTangent>::Tangent: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<T> Struct for Axis<T>
where Axis<T>: Any + Send + Sync, T: TypePath, HashMap<T, f32>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<T> Struct for ButtonInput<T>
where T: Clone + Eq + Hash + Send + Sync + 'static + TypePath, ButtonInput<T>: Any + Send + Sync, HashSet<T>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

impl<T> Struct for Time<T>
where T: Default + TypePath + FromReflect + MaybeTyped + RegisterForReflection, Time<T>: Any + Send + Sync,