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 + 'static

§

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 AnimationClipwhere Vec<Vec<VariableCurve, Global>, Global>: Reflect, HashMap<EntityPath, usize, RandomState, Global>: Reflect, f32: Reflect,

§

impl Struct for AnimationPlayerwhere bool: Reflect, PlayingAnimation: Reflect, Vec<AnimationTransition, Global>: Any + Send + Sync,

§

impl Struct for EntityPathwhere Vec<Name, Global>: Reflect,

§

impl Struct for VariableCurvewhere Vec<f32, Global>: Reflect, Keyframes: Reflect,

§

impl Struct for Namewhere u64: Reflect, Cow<'static, str>: Reflect,

§

impl Struct for BloomPrefilterSettingswhere f32: Reflect,

§

impl Struct for BloomSettingswhere f32: Reflect, BloomPrefilterSettings: Reflect, BloomCompositeMode: Reflect,

§

impl Struct for Camera2dwhere ClearColorConfig: Reflect,

§

impl Struct for Camera3dwhere ClearColorConfig: Reflect, Camera3dDepthLoadOp: Reflect,

§

impl Struct for Fxaawhere bool: Reflect, Sensitivity: Reflect,

§

impl Struct for DepthPrepass

§

impl Struct for NormalPrepass

§

impl Struct for GltfExtraswhere String: Reflect,

§

impl Struct for AxisSettingswhere f32: Reflect,

§

impl Struct for ButtonAxisSettingswhere f32: Reflect,

§

impl Struct for ButtonSettingswhere f32: Reflect,

§

impl Struct for Gamepadwhere usize: Reflect,

§

impl Struct for GamepadAxiswhere Gamepad: Reflect, GamepadAxisType: Reflect,

§

impl Struct for GamepadAxisChangedEventwhere Gamepad: Reflect, GamepadAxisType: Reflect, f32: Reflect,

§

impl Struct for GamepadButtonwhere Gamepad: Reflect, GamepadButtonType: Reflect,

§

impl Struct for GamepadButtonChangedEventwhere Gamepad: Reflect, GamepadButtonType: Reflect, f32: Reflect,

§

impl Struct for GamepadConnectionEventwhere Gamepad: Reflect, GamepadConnection: Reflect,

§

impl Struct for GamepadInfowhere String: Reflect,

§

impl Struct for GamepadSettingswhere ButtonSettings: Reflect, AxisSettings: Reflect, ButtonAxisSettings: Reflect, HashMap<GamepadButton, ButtonSettings, RandomState, Global>: Reflect, HashMap<GamepadAxis, AxisSettings, RandomState, Global>: Reflect, HashMap<GamepadButton, ButtonAxisSettings, RandomState, Global>: Reflect,

§

impl Struct for KeyboardInputwhere u32: Reflect, Option<KeyCode>: Reflect, ButtonState: Reflect,

§

impl Struct for MouseButtonInputwhere MouseButton: Reflect, ButtonState: Reflect,

§

impl Struct for MouseMotionwhere Vec2: Reflect,

§

impl Struct for MouseWheelwhere MouseScrollUnit: Reflect, f32: Reflect,

§

impl Struct for TouchInputwhere TouchPhase: Reflect, Vec2: Reflect, Option<ForceTouch>: Reflect, u64: Reflect,

§

impl Struct for BVec2where bool: Reflect,

§

impl Struct for BVec3where bool: Reflect,

§

impl Struct for BVec4where bool: Reflect,

§

impl Struct for Mat2where Vec2: Reflect,

§

impl Struct for Mat3where Vec3: Reflect,

§

impl Struct for Mat4where Vec4: Reflect,

§

impl Struct for Vec2where f32: Reflect,

§

impl Struct for Vec3where f32: Reflect,

§

impl Struct for Vec4where f32: Reflect,

§

impl Struct for IVec2where i32: Reflect,

§

impl Struct for IVec3where i32: Reflect,

§

impl Struct for IVec4where i32: Reflect,

§

impl Struct for Affine2where Mat2: Reflect, Vec2: Reflect,

§

impl Struct for Affine3Awhere Mat3A: Reflect, Vec3A: Reflect,

§

impl Struct for DAffine2where DMat2: Reflect, DVec2: Reflect,

§

impl Struct for DAffine3where DMat3: Reflect, DVec3: Reflect,

§

impl Struct for DMat2where DVec2: Reflect,

§

impl Struct for DMat3where DVec3: Reflect,

§

impl Struct for DMat4where DVec4: Reflect,

§

impl Struct for DVec2where f64: Reflect,

§

impl Struct for DVec3where f64: Reflect,

§

impl Struct for DVec4where f64: Reflect,

§

impl Struct for Mat3Awhere Vec3A: Reflect,

§

impl Struct for Rectwhere Vec2: Reflect,

§

impl Struct for Vec3Awhere f32: Reflect,

§

impl Struct for UVec2where u32: Reflect,

§

impl Struct for UVec3where u32: Reflect,

§

impl Struct for UVec4where u32: Reflect,

§

impl Struct for AmbientLightwhere Color: Reflect, f32: Reflect,

§

impl Struct for Cascadewhere Mat4: Reflect, f32: Reflect,

§

impl Struct for CascadeShadowConfigwhere Vec<f32, Global>: Reflect, f32: Reflect,

§

impl Struct for Cascadeswhere HashMap<Entity, Vec<Cascade, Global>, RandomState, Global>: Reflect,

§

impl Struct for CascadesVisibleEntitieswhere HashMap<Entity, Vec<VisibleEntities, Global>, RandomState, Global>: Any + Send + Sync,

§

impl Struct for ClusterZConfigwhere f32: Reflect, ClusterFarZMode: Reflect,

§

impl Struct for CubemapVisibleEntitieswhere [VisibleEntities; 6]: Any + Send + Sync,

§

impl Struct for DirectionalLightwhere Color: Reflect, f32: Reflect, bool: Reflect,

§

impl Struct for DirectionalLightShadowMapwhere usize: Reflect,

§

impl Struct for EnvironmentMapLightwhere Handle<Image>: Reflect,

§

impl Struct for FogSettingswhere Color: Reflect, f32: Reflect, FogFalloff: Reflect,

§

impl Struct for NotShadowCaster

§

impl Struct for NotShadowReceiver

§

impl Struct for PointLightwhere Color: Reflect, f32: Reflect, bool: Reflect,

§

impl Struct for PointLightShadowMapwhere usize: Reflect,

§

impl Struct for SpotLightwhere Color: Reflect, f32: Reflect, bool: Reflect,

§

impl Struct for StandardMaterialwhere Color: Reflect, Option<Handle<Image>>: Reflect, f32: Reflect, bool: Reflect, AlphaMode: Reflect, Option<Face>: Any + Send + Sync,

§

impl Struct for Wireframe

§

impl Struct for WireframeConfigwhere bool: Reflect,

§

impl Struct for Camerawhere Option<Viewport>: Reflect, isize: Reflect, bool: Reflect, ComputedCameraValues: Any + Send + Sync, RenderTarget: Any + Send + Sync, CameraOutputMode: Any + Send + Sync,

§

impl Struct for OrthographicProjectionwhere f32: Reflect, Vec2: Reflect, ScalingMode: Reflect, Rect: Reflect,

§

impl Struct for PerspectiveProjectionwhere f32: Reflect,

§

impl Struct for Viewportwhere UVec2: Reflect, Range<f32>: Reflect,

§

impl Struct for GlobalsUniformwhere f32: Reflect, u32: Reflect,

§

impl Struct for SkinnedMeshwhere Handle<SkinnedMeshInverseBindposes>: Reflect, Vec<Entity, Global>: Reflect,

§

impl Struct for Aabbwhere Vec3A: Reflect,

§

impl Struct for CascadesFrustawhere HashMap<Entity, Vec<Frustum, Global>, RandomState, Global>: Any + Send + Sync,

§

impl Struct for CubemapFrustawhere [Frustum; 6]: Any + Send + Sync,

§

impl Struct for Frustumwhere [Plane; 6]: Any + Send + Sync,

§

impl Struct for ColorGradingwhere f32: Reflect,

§

impl Struct for ComputedVisibilitywhere ComputedVisibilityFlags: Reflect,

§

impl Struct for VisibleEntitieswhere Vec<Entity, Global>: Any + Send + Sync,

§

impl Struct for ColorMaterialwhere Color: Reflect, Option<Handle<Image>>: Reflect,

§

impl Struct for Spritewhere Color: Reflect, bool: Reflect, Option<Vec2>: Reflect, Option<Rect>: Reflect, Anchor: Reflect,

§

impl Struct for TextureAtlaswhere Handle<Image>: Reflect, Vec2: Reflect, Vec<Rect, Global>: Reflect, Option<HashMap<Handle<Image>, usize, RandomState, Global>>: Reflect,

§

impl Struct for TextureAtlasSpritewhere Color: Reflect, usize: Reflect, bool: Reflect, Option<Vec2>: Reflect, Anchor: Reflect,

§

impl Struct for Text2dBoundswhere Vec2: Reflect,

§

impl Struct for Textwhere Vec<TextSection, Global>: Reflect, TextAlignment: Reflect, BreakLineOn: Reflect,

§

impl Struct for TextSectionwhere String: Reflect, TextStyle: Reflect,

§

impl Struct for TextStylewhere Handle<Font>: Reflect, f32: Reflect, Color: Reflect,

§

impl Struct for Stopwatchwhere Duration: Reflect, bool: Reflect,

§

impl Struct for Timewhere Instant: Reflect, Option<Instant>: Reflect, bool: Reflect, f64: Reflect, Duration: Reflect, f32: Reflect,

§

impl Struct for Timerwhere Stopwatch: Reflect, Duration: Reflect, TimerMode: Reflect, bool: Reflect, u32: Reflect,

§

impl Struct for Transformwhere Vec3: Reflect, Quat: Reflect,

§

impl Struct for CalculatedClipwhere Rect: Reflect,

§

impl Struct for CalculatedSizewhere Vec2: Reflect, bool: Reflect,

§

impl Struct for Nodewhere Vec2: Reflect,

§

impl Struct for RelativeCursorPositionwhere Option<Vec2>: Reflect,

§

impl Struct for Sizewhere Val: Reflect,

§

impl Struct for Stylewhere Display: Reflect, PositionType: Reflect, Direction: Reflect, FlexDirection: Reflect, FlexWrap: Reflect, AlignItems: Reflect, AlignSelf: Reflect, AlignContent: Reflect, JustifyContent: Reflect, UiRect: Reflect, f32: Reflect, Val: Reflect, Size: Reflect, Option<f32>: Reflect, Overflow: Reflect,

§

impl Struct for UiImagewhere Handle<Image>: Reflect, bool: Reflect,

§

impl Struct for UiRectwhere Val: Reflect,

§

impl Struct for Button

§

impl Struct for Label

§

impl Struct for Cursorwhere CursorIcon: Reflect, bool: Reflect, CursorGrabMode: Reflect, Option<DVec2>: Reflect,

§

impl Struct for CursorEnteredwhere Entity: Reflect,

§

impl Struct for CursorLeftwhere Entity: Reflect,

§

impl Struct for CursorMovedwhere Entity: Reflect, Vec2: Reflect,

§

impl Struct for InternalWindowStatewhere Option<bool>: Reflect,

§

impl Struct for PrimaryWindow

§

impl Struct for ReceivedCharacterwhere Entity: Reflect, char: Reflect,

§

impl Struct for RequestRedraw

§

impl Struct for Windowwhere Cursor: Reflect, PresentMode: Reflect, WindowMode: Reflect, WindowPosition: Reflect, WindowResolution: Reflect, String: Reflect, CompositeAlphaMode: Reflect, WindowResizeConstraints: Reflect, bool: Reflect, WindowLevel: Reflect, Option<String>: Reflect, InternalWindowState: Reflect, Vec2: Reflect,

§

impl Struct for WindowBackendScaleFactorChangedwhere Entity: Reflect, f64: Reflect,

§

impl Struct for WindowCloseRequestedwhere Entity: Reflect,

§

impl Struct for WindowClosedwhere Entity: Reflect,

§

impl Struct for WindowCreatedwhere Entity: Reflect,

§

impl Struct for WindowFocusedwhere Entity: Reflect, bool: Reflect,

§

impl Struct for WindowMovedwhere Entity: Reflect, IVec2: Reflect,

§

impl Struct for WindowResizeConstraintswhere f32: Reflect,

§

impl Struct for WindowResizedwhere Entity: Reflect, f32: Reflect,

§

impl Struct for WindowResolutionwhere u32: Reflect, Option<f64>: Reflect, f64: Reflect,

§

impl Struct for WindowScaleFactorChangedwhere Entity: Reflect, f64: Reflect,

§

impl Struct for DynamicStruct

§

impl<T> Struct for Handle<T>where T: Asset, HandleId: Reflect, HandleType: Any + Send + Sync, PhantomData<fn() -> T>: Any + Send + Sync,

§

impl<T> Struct for Input<T>where T: Copy + Eq + Hash + Send + Sync + 'static, HashSet<T, RandomState, Global>: Reflect,