Struct bevy::reflect::ParsedPath
pub struct ParsedPath(/* private fields */);
Expand description
A pre-parsed path to an element within a type.
This struct may be used like GetPath
but removes the cost of parsing the path
string at each element access.
It’s recommended to use this in place of GetPath
when the path string is
unlikely to be changed and will be accessed repeatedly.
Implementations§
§impl ParsedPath
impl ParsedPath
pub fn parse(string: &str) -> Result<ParsedPath, ReflectPathError<'_>>
pub fn parse(string: &str) -> Result<ParsedPath, ReflectPathError<'_>>
Parses a ParsedPath
from a string.
Returns an error if the string does not represent a valid path to an element.
The exact format for path strings can be found in the documentation for GetPath
.
In short, though, a path consists of one or more chained accessor strings.
These are:
- Named field access (
.field
) - Unnamed field access (
.1
) - Field index access (
#0
) - Sequence access (
[2]
)
Example
#[derive(Reflect)]
struct Foo {
bar: Bar,
}
#[derive(Reflect)]
struct Bar {
baz: Baz,
}
#[derive(Reflect)]
struct Baz(f32, Vec<Option<u32>>);
let foo = Foo {
bar: Bar {
baz: Baz(3.14, vec![None, None, Some(123)])
},
};
let parsed_path = ParsedPath::parse("bar#0.1[2].0").unwrap();
// Breakdown:
// "bar" - Access struct field named "bar"
// "#0" - Access struct field at index 0
// ".1" - Access tuple struct field at index 1
// "[2]" - Access list element at index 2
// ".0" - Access tuple variant field at index 0
assert_eq!(parsed_path.element::<u32>(&foo).unwrap(), &123);
pub fn parse_static(
string: &'static str
) -> Result<ParsedPath, ReflectPathError<'static>>
pub fn parse_static( string: &'static str ) -> Result<ParsedPath, ReflectPathError<'static>>
Similar to Self::parse
but only works on &'static str
and does not allocate per named field.
Trait Implementations§
§impl Clone for ParsedPath
impl Clone for ParsedPath
§fn clone(&self) -> ParsedPath
fn clone(&self) -> ParsedPath
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more§impl Debug for ParsedPath
impl Debug for ParsedPath
§impl Display for ParsedPath
impl Display for ParsedPath
§impl Hash for ParsedPath
impl Hash for ParsedPath
§impl Ord for ParsedPath
impl Ord for ParsedPath
§impl PartialEq<ParsedPath> for ParsedPath
impl PartialEq<ParsedPath> for ParsedPath
§fn eq(&self, other: &ParsedPath) -> bool
fn eq(&self, other: &ParsedPath) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.§impl PartialOrd<ParsedPath> for ParsedPath
impl PartialOrd<ParsedPath> for ParsedPath
§fn partial_cmp(&self, other: &ParsedPath) -> Option<Ordering>
fn partial_cmp(&self, other: &ParsedPath) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more§impl<'a> ReflectPath<'a> for &'a ParsedPath
impl<'a> ReflectPath<'a> for &'a ParsedPath
§fn reflect_element(
self,
root: &(dyn Reflect + 'static)
) -> Result<&(dyn Reflect + 'static), ReflectPathError<'a>>
fn reflect_element( self, root: &(dyn Reflect + 'static) ) -> Result<&(dyn Reflect + 'static), ReflectPathError<'a>>
§fn reflect_element_mut(
self,
root: &mut (dyn Reflect + 'static)
) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'a>>
fn reflect_element_mut( self, root: &mut (dyn Reflect + 'static) ) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'a>>
§fn element<T>(
self,
root: &(dyn Reflect + 'static)
) -> Result<&T, ReflectPathError<'a>>where
T: Reflect,
fn element<T>( self, root: &(dyn Reflect + 'static) ) -> Result<&T, ReflectPathError<'a>>where T: Reflect,
§fn element_mut<T>(
self,
root: &mut (dyn Reflect + 'static)
) -> Result<&mut T, ReflectPathError<'a>>where
T: Reflect,
fn element_mut<T>( self, root: &mut (dyn Reflect + 'static) ) -> Result<&mut T, ReflectPathError<'a>>where T: Reflect,
impl Eq for ParsedPath
impl StructuralEq for ParsedPath
impl StructuralPartialEq for ParsedPath
Auto Trait Implementations§
impl RefUnwindSafe for ParsedPath
impl Send for ParsedPath
impl Sync for ParsedPath
impl Unpin for ParsedPath
impl UnwindSafe for ParsedPath
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere U: ShaderType, &'a T: for<'a> Into<U>,
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
Return the
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.