Trait bevy::reflect::Struct

source ·
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§

source

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

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

source

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.

source

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.

source

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.

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.

source

fn clone_dynamic(&self) -> DynamicStruct

Clones the struct into a DynamicStruct.

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 AnimationClip

source§

impl Struct for AnimationPlayer

source§

impl Struct for EntityPath

source§

impl Struct for VariableCurve

source§

impl Struct for AssetIndex

source§

impl Struct for GlobalVolume

source§

impl Struct for PlaybackSettings

source§

impl Struct for SpatialListener

source§

impl Struct for Name

source§

impl Struct for BloomPrefilterSettings

source§

impl Struct for BloomSettings

source§

impl Struct for ContrastAdaptiveSharpeningSettings

source§

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

source§

impl Struct for Camera3d

source§

impl Struct for TemporalAntiAliasSettings

source§

impl Struct for Fxaa

source§

impl Struct for DeferredPrepass

source§

impl Struct for DepthPrepass

source§

impl Struct for MotionVectorPrepass

source§

impl Struct for NormalPrepass

source§

impl Struct for ComponentTicks

source§

impl Struct for Tick

source§

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

source§

impl Struct for AabbGizmoConfigGroup

source§

impl Struct for ShowAabbGizmo

source§

impl Struct for DefaultGizmoConfigGroup

source§

impl Struct for GizmoConfig

source§

impl Struct for GltfExtras

source§

impl Struct for AxisSettings

source§

impl Struct for ButtonAxisSettings

source§

impl Struct for ButtonSettings

source§

impl Struct for Gamepad

source§

impl Struct for GamepadAxis

source§

impl Struct for GamepadAxisChangedEvent

source§

impl Struct for GamepadButton

source§

impl Struct for GamepadButtonChangedEvent

source§

impl Struct for GamepadButtonInput

source§

impl Struct for GamepadConnectionEvent

source§

impl Struct for GamepadInfo

source§

impl Struct for GamepadSettings

source§

impl Struct for KeyboardInput

source§

impl Struct for MouseButtonInput

source§

impl Struct for MouseMotion

source§

impl Struct for MouseWheel

source§

impl Struct for TouchInput

source§

impl Struct for BVec2

source§

impl Struct for BVec3

source§

impl Struct for BVec4

source§

impl Struct for Mat2

source§

impl Struct for Mat3

source§

impl Struct for Mat4

source§

impl Struct for Quat

source§

impl Struct for Vec2

source§

impl Struct for Vec3

source§

impl Struct for Vec4

source§

impl Struct for IVec2

source§

impl Struct for IVec3

source§

impl Struct for IVec4

source§

impl Struct for Capsule2d

source§

impl Struct for Capsule3d

source§

impl Struct for Circle

source§

impl Struct for Cone

source§

impl Struct for ConicalFrustum

source§

impl Struct for Cuboid

source§

impl Struct for Cylinder

source§

impl Struct for Ellipse

source§

impl Struct for Line2d

source§

impl Struct for Line3d

source§

impl Struct for Plane2d

source§

impl Struct for Plane3d

source§

impl Struct for Rectangle

source§

impl Struct for RegularPolygon

source§

impl Struct for Segment2d

source§

impl Struct for Segment3d

source§

impl Struct for Sphere

source§

impl Struct for Torus

source§

impl Struct for Triangle2d

source§

impl Struct for Affine2

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 I64Vec2

source§

impl Struct for I64Vec3

source§

impl Struct for I64Vec4

source§

impl Struct for IRect

source§

impl Struct for Mat3A

source§

impl Struct for Rect

source§

impl Struct for U64Vec2

source§

impl Struct for U64Vec3

source§

impl Struct for U64Vec4

source§

impl Struct for URect

source§

impl Struct for Vec3A

source§

impl Struct for UVec2

source§

impl Struct for UVec3

source§

impl Struct for UVec4

source§

impl Struct for EnvironmentMapLight

source§

impl Struct for IrradianceVolume

source§

impl Struct for AmbientLight

source§

impl Struct for Cascade

source§

impl Struct for CascadeShadowConfig

source§

impl Struct for Cascades

source§

impl Struct for CascadesVisibleEntities

source§

impl Struct for ClusterZConfig

source§

impl Struct for CubemapVisibleEntities

source§

impl Struct for DirectionalLight

source§

impl Struct for DirectionalLightShadowMap

source§

impl Struct for FogSettings

source§

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

source§

impl Struct for Lightmap

source§

impl Struct for NotShadowCaster

source§

impl Struct for NotShadowReceiver

source§

impl Struct for PointLight

source§

impl Struct for PointLightShadowMap

source§

impl Struct for ScreenSpaceAmbientOcclusionSettings

source§

impl Struct for SpotLight

source§

impl Struct for StandardMaterial

source§

impl Struct for TransmittedShadowReceiver

source§

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

source§

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

source§

impl Struct for WireframeColor

source§

impl Struct for WireframeConfig

source§

impl Struct for Camera

source§

impl Struct for OrthographicProjection

source§

impl Struct for PerspectiveProjection

source§

impl Struct for Viewport

source§

impl Struct for GlobalsUniform

source§

impl Struct for MeshMorphWeights

source§

impl Struct for MorphWeights

source§

impl Struct for SkinnedMesh

source§

impl Struct for Mesh

source§

impl Struct for Aabb

source§

impl Struct for CascadesFrusta

source§

impl Struct for CubemapFrusta

source§

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

source§

impl Struct for ColorGrading

source§

impl Struct for NoFrustumCulling

source§

impl Struct for VisibleEntities

source§

impl Struct for BorderRect

source§

impl Struct for ColorMaterial

source§

impl Struct for Sprite

source§

impl Struct for TextureAtlas

source§

impl Struct for TextureAtlasLayout

source§

impl Struct for TextureSlicer

source§

impl Struct for GlyphAtlasInfo

source§

impl Struct for PositionedGlyph

source§

impl Struct for Text2dBounds

source§

impl Struct for Text

source§

impl Struct for TextLayoutInfo

source§

impl Struct for TextSection

source§

impl Struct for TextStyle

source§

impl Struct for Fixed

source§

impl Struct for Real

source§

impl Struct for Stopwatch

source§

impl Struct for Timer

source§

impl Struct for Virtual

source§

impl Struct for Transform

source§

impl Struct for CalculatedClip

source§

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

source§

impl Struct for GridPlacement

source§

impl Struct for GridTrack

source§

impl Struct for Node

source§

impl Struct for Outline

source§

impl Struct for Overflow

source§

impl Struct for RelativeCursorPosition

source§

impl Struct for RepeatedGridTrack

source§

impl Struct for Style

source§

impl Struct for UiImage

source§

impl Struct for UiRect

source§

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

source§

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

source§

impl Struct for TextFlags

source§

impl Struct for UiImageSize

source§

impl Struct for Cursor

source§

impl Struct for CursorEntered

source§

impl Struct for CursorLeft

source§

impl Struct for CursorMoved

source§

impl Struct for EnabledButtons

source§

impl Struct for InternalWindowState

source§

impl Struct for PrimaryWindow

source§

impl Struct for ReceivedCharacter

source§

impl Struct for RequestRedraw

source§

impl Struct for Window

source§

impl Struct for WindowBackendScaleFactorChanged

source§

impl Struct for WindowCloseRequested

source§

impl Struct for WindowClosed

source§

impl Struct for WindowCreated

source§

impl Struct for WindowDestroyed

source§

impl Struct for WindowFocused

source§

impl Struct for WindowMoved

source§

impl Struct for WindowOccluded

source§

impl Struct for WindowResizeConstraints

source§

impl Struct for WindowResized

source§

impl Struct for WindowResolution

source§

impl Struct for WindowScaleFactorChanged

source§

impl Struct for WindowThemeChanged

source§

impl Struct for DynamicStruct

source§

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

source§

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

source§

impl<T> Struct for Time<T>

source§

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

source§

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

source§

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