Trait bevy::reflect::Struct

pub trait Struct: Reflect {
    // Required methods
    fn field(&self, name: &str) -> Option<&(dyn Reflect + 'static)>;
    fn field_mut(&mut self, name: &str) -> Option<&mut (dyn Reflect + 'static)>;
    fn field_at(&self, index: usize) -> Option<&(dyn Reflect + 'static)>;
    fn field_at_mut(
        &mut self,
        index: usize
    ) -> Option<&mut (dyn Reflect + 'static)>;
    fn name_at(&self, index: usize) -> Option<&str>;
    fn field_len(&self) -> usize;
    fn iter_fields(&self) -> FieldIter<'_> ;
    fn clone_dynamic(&self) -> DynamicStruct;
}
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::{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 Reflect = foo.field("bar").unwrap();
assert_eq!(field.downcast_ref::<u32>(), Some(&123));

Required Methods§

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

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

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

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

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

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

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

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

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

Returns the name of the field with index index.

fn field_len(&self) -> usize

Returns the number of fields in the struct.

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

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

fn clone_dynamic(&self) -> DynamicStruct

Clones the struct into a DynamicStruct.

Trait Implementations§

§

impl GetField for dyn Struct

§

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.
§

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§

§

impl Struct for AnimationClip

§

impl Struct for AnimationPlayer

§

impl Struct for EntityPath

§

impl Struct for VariableCurve

§

impl Struct for AssetIndex

§

impl Struct for GlobalVolume

§

impl Struct for PlaybackSettings

§

impl Struct for SpatialListener

§

impl Struct for Name

§

impl Struct for BloomPrefilterSettings

§

impl Struct for BloomSettings

§

impl Struct for ContrastAdaptiveSharpeningSettings

§

impl Struct for Camera2d
where Camera2d: Any + Send + Sync,

§

impl Struct for Camera3d

§

impl Struct for TemporalAntiAliasSettings

§

impl Struct for Fxaa

§

impl Struct for DeferredPrepass

§

impl Struct for DepthPrepass

§

impl Struct for MotionVectorPrepass

§

impl Struct for NormalPrepass

§

impl Struct for ComponentTicks

§

impl Struct for Tick

§

impl Struct for EntityHash
where EntityHash: Any + Send + Sync,

§

impl Struct for AabbGizmoConfigGroup

§

impl Struct for ShowAabbGizmo

§

impl Struct for DefaultGizmoConfigGroup

§

impl Struct for GizmoConfig

§

impl Struct for GltfExtras

§

impl Struct for AxisSettings

§

impl Struct for ButtonAxisSettings

§

impl Struct for ButtonSettings

§

impl Struct for Gamepad

§

impl Struct for GamepadAxis

§

impl Struct for GamepadAxisChangedEvent

§

impl Struct for GamepadButton

§

impl Struct for GamepadButtonChangedEvent

§

impl Struct for GamepadButtonInput

§

impl Struct for GamepadConnectionEvent

§

impl Struct for GamepadInfo

§

impl Struct for GamepadSettings

§

impl Struct for KeyboardInput

§

impl Struct for MouseButtonInput

§

impl Struct for MouseMotion

§

impl Struct for MouseWheel

§

impl Struct for TouchInput

§

impl Struct for BVec2

§

impl Struct for BVec3

§

impl Struct for BVec4

§

impl Struct for Mat2

§

impl Struct for Mat3

§

impl Struct for Mat4

§

impl Struct for Quat

§

impl Struct for Vec2

§

impl Struct for Vec3

§

impl Struct for Vec4

§

impl Struct for IVec2

§

impl Struct for IVec3

§

impl Struct for IVec4

§

impl Struct for Capsule2d

§

impl Struct for Capsule3d

§

impl Struct for Circle

§

impl Struct for Cone

§

impl Struct for ConicalFrustum

§

impl Struct for Cuboid

§

impl Struct for Cylinder

§

impl Struct for Ellipse

§

impl Struct for Line2d

§

impl Struct for Line3d

§

impl Struct for Plane2d

§

impl Struct for Plane3d

§

impl Struct for Rectangle

§

impl Struct for RegularPolygon

§

impl Struct for Segment2d

§

impl Struct for Segment3d

§

impl Struct for Sphere

§

impl Struct for Torus

§

impl Struct for Triangle2d

§

impl Struct for Affine2

§

impl Struct for Affine3A

§

impl Struct for DAffine2

§

impl Struct for DAffine3

§

impl Struct for DMat2

§

impl Struct for DMat3

§

impl Struct for DMat4

§

impl Struct for DQuat

§

impl Struct for DVec2

§

impl Struct for DVec3

§

impl Struct for DVec4

§

impl Struct for I64Vec2

§

impl Struct for I64Vec3

§

impl Struct for I64Vec4

§

impl Struct for IRect

§

impl Struct for Mat3A

§

impl Struct for Rect

§

impl Struct for U64Vec2

§

impl Struct for U64Vec3

§

impl Struct for U64Vec4

§

impl Struct for URect

§

impl Struct for Vec3A

§

impl Struct for UVec2

§

impl Struct for UVec3

§

impl Struct for UVec4

§

impl Struct for EnvironmentMapLight

§

impl Struct for IrradianceVolume

§

impl Struct for AmbientLight

§

impl Struct for Cascade

§

impl Struct for CascadeShadowConfig

§

impl Struct for Cascades

§

impl Struct for CascadesVisibleEntities

§

impl Struct for ClusterZConfig

§

impl Struct for CubemapVisibleEntities

§

impl Struct for DirectionalLight

§

impl Struct for DirectionalLightShadowMap

§

impl Struct for FogSettings

§

impl Struct for LightProbe
where LightProbe: Any + Send + Sync,

§

impl Struct for Lightmap

§

impl Struct for NotShadowCaster

§

impl Struct for NotShadowReceiver

§

impl Struct for PointLight

§

impl Struct for PointLightShadowMap

§

impl Struct for ScreenSpaceAmbientOcclusionSettings

§

impl Struct for SpotLight

§

impl Struct for StandardMaterial

§

impl Struct for TransmittedShadowReceiver

§

impl Struct for NoWireframe
where NoWireframe: Any + Send + Sync,

§

impl Struct for Wireframe
where Wireframe: Any + Send + Sync,

§

impl Struct for WireframeColor

§

impl Struct for WireframeConfig

§

impl Struct for Camera

§

impl Struct for OrthographicProjection

§

impl Struct for PerspectiveProjection

§

impl Struct for Viewport

§

impl Struct for GlobalsUniform

§

impl Struct for MeshMorphWeights

§

impl Struct for MorphWeights

§

impl Struct for SkinnedMesh

§

impl Struct for Mesh

§

impl Struct for Aabb

§

impl Struct for CascadesFrusta

§

impl Struct for CubemapFrusta

§

impl Struct for Frustum
where Frustum: Any + Send + Sync,

§

impl Struct for ColorGrading

§

impl Struct for NoFrustumCulling

§

impl Struct for VisibleEntities

§

impl Struct for BorderRect

§

impl Struct for ColorMaterial

§

impl Struct for Sprite

§

impl Struct for TextureAtlas

§

impl Struct for TextureAtlasLayout

§

impl Struct for TextureSlicer

§

impl Struct for GlyphAtlasInfo

§

impl Struct for PositionedGlyph

§

impl Struct for Text2dBounds

§

impl Struct for Text

§

impl Struct for TextLayoutInfo

§

impl Struct for TextSection

§

impl Struct for TextStyle

§

impl Struct for Fixed

§

impl Struct for Real

§

impl Struct for Stopwatch

§

impl Struct for Timer

§

impl Struct for Virtual

§

impl Struct for Transform

§

impl Struct for CalculatedClip

§

impl Struct for ContentSize
where ContentSize: Any + Send + Sync,

§

impl Struct for GridPlacement

§

impl Struct for GridTrack

§

impl Struct for Node

§

impl Struct for Outline

§

impl Struct for Overflow

§

impl Struct for RelativeCursorPosition

§

impl Struct for RepeatedGridTrack

§

impl Struct for Style

§

impl Struct for UiImage

§

impl Struct for UiRect

§

impl Struct for Button
where Button: Any + Send + Sync,

§

impl Struct for Label
where Label: Any + Send + Sync,

§

impl Struct for TextFlags

§

impl Struct for UiImageSize

§

impl Struct for Cursor

§

impl Struct for CursorEntered

§

impl Struct for CursorLeft

§

impl Struct for CursorMoved

§

impl Struct for EnabledButtons

§

impl Struct for InternalWindowState

§

impl Struct for PrimaryWindow

§

impl Struct for ReceivedCharacter

§

impl Struct for RequestRedraw

§

impl Struct for Window

§

impl Struct for WindowBackendScaleFactorChanged

§

impl Struct for WindowCloseRequested

§

impl Struct for WindowClosed

§

impl Struct for WindowCreated

§

impl Struct for WindowDestroyed

§

impl Struct for WindowFocused

§

impl Struct for WindowMoved

§

impl Struct for WindowOccluded

§

impl Struct for WindowResizeConstraints

§

impl Struct for WindowResized

§

impl Struct for WindowResolution

§

impl Struct for WindowScaleFactorChanged

§

impl Struct for WindowThemeChanged

§

impl Struct for DynamicStruct

§

impl<B, E> Struct for ExtendedMaterial<B, E>

§

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

§

impl<T> Struct for Time<T>

§

impl<const N: usize> Struct for Polygon<N>
where Polygon<N>: Any + Send + Sync, [Vec2; N]: FromReflect + TypePath,

§

impl<const N: usize> Struct for Polyline2d<N>

§

impl<const N: usize> Struct for Polyline3d<N>