Skip to main content

ObjectRef

Struct ObjectRef 

Source
pub struct ObjectRef<'a> { /* private fields */ }
Expand description

Borrowed reflective view of a Meta value.

§Example

let values = vec![23_u8, 23, 42];
let view = ObjectRef::new(&values);

assert_eq!(view.item(1).and_then(|item| item.to_ref::<u8>()), Some(&23));
assert_eq!(view.to_ref::<Vec<u8>>(), Some(&values));

Implementations§

Source§

impl<'a> ObjectRef<'a>

Source

pub fn new(inner: &'a dyn Meta) -> Self

Creates a borrowed object reference.

Source

pub fn as_meta(&self) -> &'a dyn Meta

Returns the underlying Meta trait object.

Source

pub fn type_info(&self) -> TypeInfo

Returns runtime type metadata for the referenced value.

Source

pub fn type_name(&self) -> &'static str

Returns the Rust type name of the referenced value.

Source

pub fn type_id(&self) -> TypeId

Returns the concrete type ID of the referenced value.

Source

pub fn kind(&self) -> ValueKind

Determines the structural shape of the referenced value.

Source

pub fn access_kind(&self) -> Option<AccessKind>

Returns the access kind of the referenced value, if any.

An option reports the access of its contained value.

Source

pub fn option_value(&self) -> Option<ObjectRef<'a>>

Returns the contained value when this reference points to Some(value).

Source

pub fn variant(&self, name: &str) -> Option<ObjectRef<'a>>

Returns the value when it is an enum whose active variant is name, forwarding through options.

Source

pub fn variant_name(&self) -> Option<&'static str>

Returns the name of the active enum variant, forwarding through options.

Source

pub fn field(&self, name: &str) -> Option<ObjectRef<'a>>

Returns an exposed field by name; see Meta::field_dyn.

Source

pub fn field_names(&self) -> &'static [&'static str]

Returns the exposed field names in declaration order.

An enum exposes the fields of its active variant.

Source

pub fn item(&self, index: usize) -> Option<ObjectRef<'a>>

Returns an item at index; see Meta::item_dyn.

Source

pub fn len(&self) -> Option<usize>

Returns the number of exposed structural items, when available.

For maps, this is the number of keyed entries. An option has one item when it holds a value.

Source

pub fn is_empty(&self) -> Option<bool>

Checks whether a value has no exposed structural items, when available.

Source

pub fn key(&self, key: &str) -> Option<ObjectRef<'a>>

Returns a value for a string-like key; see Meta::key_dyn.

Source

pub fn keys(&self) -> Option<Vec<String>>

Returns the keys as strings for map-like access or a keyed sequence.

Source

pub fn visit_map_entries(&self, visitor: &mut MapEntryVisitor<'_>) -> bool

Passes each map entry to visitor until it returns false.

Returns false when the value has no map-like access. Stopping early still returns true.

Source

pub fn to_ref<T: 'static>(&self) -> Option<&'a T>

Downcasts the reference to T.

Source

pub fn is<T: 'static>(&self) -> bool

Checks whether the referenced value has type T.

Source

pub fn field_path<Q: FieldPathQuery<'a>>(&self, query: Q) -> Option<Q::Output>

Traverses a nested field, item or key path. Accepts a raw &[PathSegment] (returns ObjectRef) or a typed TypedPath (returns &'a Value); see FieldPathQuery.

Trait Implementations§

Source§

impl<'a> Clone for ObjectRef<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for ObjectRef<'a>

Source§

impl Debug for ObjectRef<'_>

Source§

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

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

impl<'a> From<ObjectRefMut<'a>> for ObjectRef<'a>

Converts a mutable view into a shared view that keeps the lifetime 'a.

Source§

fn from(value: ObjectRefMut<'a>) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ObjectRef<'_>

Structural equality via Meta::eq_dyn.

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for ObjectRef<'a>

§

impl<'a> !Send for ObjectRef<'a>

§

impl<'a> !Sync for ObjectRef<'a>

§

impl<'a> !UnwindSafe for ObjectRef<'a>

§

impl<'a> Freeze for ObjectRef<'a>

§

impl<'a> Unpin for ObjectRef<'a>

§

impl<'a> UnsafeUnpin for ObjectRef<'a>

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, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.