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

§

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

§

impl Struct for EntityPathwhere Vec<Name>: FromReflect,

§

impl Struct for VariableCurvewhere Vec<f32>: FromReflect, Keyframes: FromReflect,

§

impl Struct for AssetIndexwhere u32: FromReflect,

§

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

§

impl Struct for BloomPrefilterSettingswhere f32: FromReflect,

§

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

§

impl Struct for ContrastAdaptiveSharpeningSettingswhere bool: FromReflect, f32: FromReflect,

§

impl Struct for Camera2dwhere ClearColorConfig: FromReflect,

§

impl Struct for Camera3dwhere ClearColorConfig: FromReflect, Camera3dDepthLoadOp: FromReflect, Camera3dDepthTextureUsage: FromReflect, usize: FromReflect, ScreenSpaceTransmissionQuality: FromReflect,

§

impl Struct for TemporalAntiAliasSettingswhere bool: FromReflect,

§

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

§

impl Struct for DeferredPrepass

§

impl Struct for DepthPrepass

§

impl Struct for MotionVectorPrepass

§

impl Struct for NormalPrepass

§

impl Struct for AabbGizmowhere Option<Color>: FromReflect,

§

impl Struct for GltfExtraswhere String: FromReflect,

§

impl Struct for AxisSettingswhere f32: FromReflect,

§

impl Struct for ButtonAxisSettingswhere f32: FromReflect,

§

impl Struct for ButtonSettingswhere f32: FromReflect,

§

impl Struct for Gamepadwhere usize: FromReflect,

§

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

§

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

§

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

§

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

§

impl Struct for GamepadButtonInputwhere GamepadButton: FromReflect, ButtonState: FromReflect,

§

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

§

impl Struct for GamepadInfowhere String: FromReflect,

§

impl Struct for GamepadSettingswhere ButtonSettings: FromReflect, AxisSettings: FromReflect, ButtonAxisSettings: FromReflect, HashMap<GamepadButton, ButtonSettings>: FromReflect, HashMap<GamepadAxis, AxisSettings>: FromReflect, HashMap<GamepadButton, ButtonAxisSettings>: FromReflect,

§

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

§

impl Struct for MouseButtonInputwhere MouseButton: FromReflect, ButtonState: FromReflect, Entity: FromReflect,

§

impl Struct for MouseMotionwhere Vec2: FromReflect,

§

impl Struct for MouseWheelwhere MouseScrollUnit: FromReflect, f32: FromReflect, Entity: FromReflect,

§

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

§

impl Struct for BVec2where bool: FromReflect,

§

impl Struct for BVec3where bool: FromReflect,

§

impl Struct for BVec4where bool: FromReflect,

§

impl Struct for Mat2where Vec2: FromReflect,

§

impl Struct for Mat3where Vec3: FromReflect,

§

impl Struct for Mat4where Vec4: FromReflect,

§

impl Struct for Quatwhere f32: FromReflect,

§

impl Struct for Vec2where f32: FromReflect,

§

impl Struct for Vec3where f32: FromReflect,

§

impl Struct for Vec4where f32: FromReflect,

§

impl Struct for IVec2where i32: FromReflect,

§

impl Struct for IVec3where i32: FromReflect,

§

impl Struct for IVec4where i32: FromReflect,

§

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

§

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

§

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

§

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

§

impl Struct for DMat2where DVec2: FromReflect,

§

impl Struct for DMat3where DVec3: FromReflect,

§

impl Struct for DMat4where DVec4: FromReflect,

§

impl Struct for DQuatwhere f64: FromReflect,

§

impl Struct for DVec2where f64: FromReflect,

§

impl Struct for DVec3where f64: FromReflect,

§

impl Struct for DVec4where f64: FromReflect,

§

impl Struct for I64Vec2where i64: FromReflect,

§

impl Struct for I64Vec3where i64: FromReflect,

§

impl Struct for I64Vec4where i64: FromReflect,

§

impl Struct for IRectwhere IVec2: FromReflect,

§

impl Struct for Mat3Awhere Vec3A: FromReflect,

§

impl Struct for Rectwhere Vec2: FromReflect,

§

impl Struct for U64Vec2where u64: FromReflect,

§

impl Struct for U64Vec3where u64: FromReflect,

§

impl Struct for U64Vec4where u64: FromReflect,

§

impl Struct for URectwhere UVec2: FromReflect,

§

impl Struct for Vec3Awhere f32: FromReflect,

§

impl Struct for UVec2where u32: FromReflect,

§

impl Struct for UVec3where u32: FromReflect,

§

impl Struct for UVec4where u32: FromReflect,

§

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

§

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

§

impl Struct for CascadeShadowConfigwhere Vec<f32>: FromReflect, f32: FromReflect,

§

impl Struct for Cascadeswhere HashMap<Entity, Vec<Cascade>>: FromReflect,

§

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

§

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

§

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

§

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

§

impl Struct for DirectionalLightShadowMapwhere usize: FromReflect,

§

impl Struct for EnvironmentMapLightwhere Handle<Image>: FromReflect,

§

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

§

impl Struct for NotShadowCaster

§

impl Struct for NotShadowReceiver

§

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

§

impl Struct for PointLightShadowMapwhere usize: FromReflect,

§

impl Struct for ScreenSpaceAmbientOcclusionSettingswhere ScreenSpaceAmbientOcclusionQualityLevel: FromReflect,

§

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

§

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

§

impl Struct for TransmittedShadowReceiver

§

impl Struct for NoWireframe

§

impl Struct for Wireframe

§

impl Struct for WireframeColorwhere Color: FromReflect,

§

impl Struct for WireframeConfigwhere bool: FromReflect, Color: FromReflect,

§

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

§

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

§

impl Struct for PerspectiveProjectionwhere f32: FromReflect,

§

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

§

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

§

impl Struct for MeshMorphWeightswhere Vec<f32>: FromReflect,

§

impl Struct for MorphWeightswhere Vec<f32>: FromReflect, Option<Handle<Mesh>>: FromReflect,

§

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

§

impl Struct for Meshwhere Option<Indices>: FromReflect, Option<Handle<Image>>: FromReflect, Option<Vec<String>>: FromReflect, PrimitiveTopology: Any + Send + Sync, BTreeMap<MeshVertexAttributeId, MeshAttributeData>: Any + Send + Sync,

§

impl Struct for Aabbwhere Vec3A: FromReflect,

§

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

§

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

§

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

§

impl Struct for ColorGradingwhere f32: FromReflect,

§

impl Struct for NoFrustumCulling

§

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

§

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

§

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

§

impl Struct for TextureAtlaswhere Handle<Image>: FromReflect, Vec2: FromReflect, Vec<Rect>: FromReflect, Option<HashMap<AssetId<Image>, usize>>: FromReflect,

§

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

§

impl Struct for GlyphAtlasInfowhere Handle<TextureAtlas>: FromReflect, usize: FromReflect,

§

impl Struct for PositionedGlyphwhere Vec2: FromReflect, GlyphAtlasInfo: FromReflect, usize: FromReflect,

§

impl Struct for Text2dBoundswhere Vec2: FromReflect,

§

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

§

impl Struct for TextLayoutInfowhere Vec<PositionedGlyph>: FromReflect, Vec2: FromReflect,

§

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

§

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

§

impl Struct for Fixedwhere Duration: FromReflect,

§

impl Struct for Realwhere Instant: FromReflect, Option<Instant>: FromReflect,

§

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

§

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

§

impl Struct for Virtualwhere Duration: FromReflect, bool: FromReflect, f64: FromReflect,

§

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

§

impl Struct for UiCameraConfigwhere bool: FromReflect,

§

impl Struct for CalculatedClipwhere Rect: FromReflect,

§

impl Struct for ContentSizewhere Option<MeasureFunc>: Any + Send + Sync,

§

impl Struct for GridPlacementwhere Option<NonZeroI16>: FromReflect, Option<NonZeroU16>: FromReflect,

§

impl Struct for GridTrackwhere MinTrackSizingFunction: FromReflect, MaxTrackSizingFunction: FromReflect,

§

impl Struct for Nodewhere u32: FromReflect, Vec2: FromReflect, f32: FromReflect,

§

impl Struct for Outlinewhere Val: FromReflect, Color: FromReflect,

§

impl Struct for Overflowwhere OverflowAxis: FromReflect,

§

impl Struct for RelativeCursorPositionwhere Option<Vec2>: FromReflect,

§

impl Struct for RepeatedGridTrackwhere GridTrackRepetition: FromReflect, SmallVec<[GridTrack; 1]>: FromReflect,

§

impl Struct for Stylewhere Display: FromReflect, PositionType: FromReflect, Overflow: FromReflect, Direction: FromReflect, Val: FromReflect, Option<f32>: FromReflect, AlignItems: FromReflect, JustifyItems: FromReflect, AlignSelf: FromReflect, JustifySelf: FromReflect, AlignContent: FromReflect, JustifyContent: FromReflect, UiRect: FromReflect, FlexDirection: FromReflect, FlexWrap: FromReflect, f32: FromReflect, GridAutoFlow: FromReflect, Vec<RepeatedGridTrack>: FromReflect, Vec<GridTrack>: FromReflect, GridPlacement: FromReflect,

§

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

§

impl Struct for UiRectwhere Val: FromReflect,

§

impl Struct for UiTextureAtlasImagewhere usize: FromReflect, bool: FromReflect,

§

impl Struct for Button

§

impl Struct for Label

§

impl Struct for TextFlagswhere bool: FromReflect,

§

impl Struct for UiImageSizewhere Vec2: FromReflect,

§

impl Struct for Cursorwhere CursorIcon: FromReflect, bool: FromReflect, CursorGrabMode: FromReflect,

§

impl Struct for CursorEnteredwhere Entity: FromReflect,

§

impl Struct for CursorLeftwhere Entity: FromReflect,

§

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

§

impl Struct for EnabledButtonswhere bool: FromReflect,

§

impl Struct for InternalWindowStatewhere Option<bool>: FromReflect, Option<DVec2>: FromReflect,

§

impl Struct for PrimaryWindow

§

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

§

impl Struct for RequestRedraw

§

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

§

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

§

impl Struct for WindowCloseRequestedwhere Entity: FromReflect,

§

impl Struct for WindowClosedwhere Entity: FromReflect,

§

impl Struct for WindowCreatedwhere Entity: FromReflect,

§

impl Struct for WindowDestroyedwhere Entity: FromReflect,

§

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

§

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

§

impl Struct for WindowResizeConstraintswhere f32: FromReflect,

§

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

§

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

§

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

§

impl Struct for WindowThemeChangedwhere Entity: FromReflect, WindowTheme: FromReflect,

§

impl Struct for DynamicStruct

§

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

§

impl<T> Struct for Time<T>where T: Default + FromReflect + TypePath, Duration: FromReflect, f32: FromReflect, f64: FromReflect,