bevy_reflect

Struct ParsedPath

Source
pub struct ParsedPath(pub Vec<OffsetAccess>);
Expand description

A pre-parsed path to an element within a type.

This struct can be constructed manually from its Accesses or with the parse method.

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.

§Examples

Parsing a &'static str:

let my_static_string: &'static str = "bar#0.1[2].0";
// 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
let my_path = ParsedPath::parse_static(my_static_string);

Parsing a non-static &str:

let my_string = String::from("bar#0.1[2].0");
// 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
let my_path = ParsedPath::parse(&my_string);

Manually constructing a ParsedPath:

let path_elements = [
    Access::Field(Cow::Borrowed("bar")),
    Access::FieldIndex(0),
    Access::TupleIndex(1),
    Access::ListIndex(2),
    Access::TupleIndex(1),
];
let my_path = ParsedPath::from(path_elements);

Tuple Fields§

§0: Vec<OffsetAccess>

This is a vector of pre-parsed OffsetAccesses.

Implementations§

Source§

impl ParsedPath

Source

pub fn parse(string: &str) -> Result<Self, 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);
Source

pub fn parse_static( string: &'static str, ) -> Result<Self, ReflectPathError<'static>>

Similar to Self::parse but only works on &'static str and does not allocate per named field.

Trait Implementations§

Source§

impl Clone for ParsedPath

Source§

fn clone(&self) -> ParsedPath

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParsedPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ParsedPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> From<[Access<'static>; N]> for ParsedPath

Source§

fn from(value: [Access<'static>; N]) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<[OffsetAccess; N]> for ParsedPath

Source§

fn from(value: [OffsetAccess; N]) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Access<'static>>> for ParsedPath

Source§

fn from(value: Vec<Access<'static>>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<OffsetAccess>> for ParsedPath

Source§

fn from(value: Vec<OffsetAccess>) -> Self

Converts to this type from the input type.
Source§

impl Hash for ParsedPath

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Index<usize> for ParsedPath

Source§

type Output = OffsetAccess

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for ParsedPath

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Ord for ParsedPath

Source§

fn cmp(&self, other: &ParsedPath) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for ParsedPath

Source§

fn eq(&self, other: &ParsedPath) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for ParsedPath

Source§

fn partial_cmp(&self, other: &ParsedPath) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a> ReflectPath<'a> for &'a ParsedPath

Source§

fn reflect_element( self, root: &dyn PartialReflect, ) -> Result<&dyn PartialReflect, ReflectPathError<'a>>

Gets a reference to the specified element on the given Reflect object. Read more
Source§

fn reflect_element_mut( self, root: &mut dyn PartialReflect, ) -> Result<&mut dyn PartialReflect, ReflectPathError<'a>>

Gets a mutable reference to the specified element on the given Reflect object. Read more
Source§

fn element<T: Reflect>( self, root: &dyn PartialReflect, ) -> Result<&T, ReflectPathError<'a>>

Gets a &T to the specified element on the given Reflect object. Read more
Source§

fn element_mut<T: Reflect>( self, root: &mut dyn PartialReflect, ) -> Result<&mut T, ReflectPathError<'a>>

Gets a &mut T to the specified element on the given Reflect object. Read more
Source§

impl<'a> TryFrom<&'a str> for ParsedPath

Source§

type Error = ReflectPathError<'a>

The type returned in the event of a conversion error.
Source§

fn try_from(value: &'a str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for ParsedPath

Source§

impl StructuralPartialEq for ParsedPath

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

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

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

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,