SnapshotField

Enum SnapshotField 

Source
#[non_exhaustive]
pub enum SnapshotField<'a> { Value(&'a RenderedValue), PercpuKey { key: u32, }, Missing(SnapshotError), }
Expand description

One field’s view at the leaf of a dotted-path walk.

Returned by super::Snapshot::var, super::SnapshotEntry::get, and super::SnapshotEntry::key. Terminal as_* accessors return SnapshotResult so a missing or type-mismatched field surfaces as a recoverable error rather than a panic.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Value(&'a RenderedValue)

Resolved rendered value at the leaf of the path walk.

§

PercpuKey

Dedicated per-CPU array key shape (u32, no struct).

Fields

§key: u32
§

Missing(SnapshotError)

Path could not be resolved.

Implementations§

Source§

impl<'a> SnapshotField<'a>

Source

pub fn get(&self, path: &str) -> SnapshotField<'a>

Walk into a sub-field. Composable with super::SnapshotEntry::get.

Source

pub fn is_present(&self) -> bool

True when the field resolved successfully.

Source

pub fn as_u64(&self) -> SnapshotResult<u64>

Read as u64. Accepts RenderedValue::Uint, RenderedValue::Int (errors on negative), RenderedValue::Bool (0/1), RenderedValue::Char (raw byte), RenderedValue::Enum (raw enum integer), RenderedValue::Ptr (pointer value), and the percpu-array u32 key.

Source

pub fn as_i64(&self) -> SnapshotResult<i64>

Read as i64.

Source

pub fn as_bool(&self) -> SnapshotResult<bool>

Read as bool. RenderedValue::Bool direct, ints / enums non-zero is true.

Source

pub fn as_f64(&self) -> SnapshotResult<f64>

Read as f64.

Source

pub fn as_str(&self) -> SnapshotResult<&'a str>

Read the variant string for an RenderedValue::Enum with a resolved variant name.

Source

pub fn as_u64_array(&self) -> SnapshotResult<Vec<u64>>

Read as Vec<u64> from an RenderedValue::Array whose every element coerces via Self::as_u64’s rules. Errors with SnapshotError::TypeMismatch when self is not an array, or when any element fails the coercion (no partial results — the caller cannot tell which element silently dropped). Mirrors RenderedValue::as_u64_array but propagates the captured SnapshotError through the SnapshotField::Missing arm.

Source

pub fn as_u32_array(&self) -> SnapshotResult<Vec<u32>>

Read as Vec<u32> from an array. Mirrors RenderedValue::as_u32_array; out-of-range values (Uint exceeding u32::MAX) error rather than truncate.

Source

pub fn as_i64_array(&self) -> SnapshotResult<Vec<i64>>

Read as Vec<i64> from an array. Mirrors RenderedValue::as_i64_array.

Source

pub fn as_f64_array(&self) -> SnapshotResult<Vec<f64>>

Read as Vec<f64> from an array. Mirrors RenderedValue::as_f64_array.

Source

pub fn as_bool_array(&self) -> SnapshotResult<Vec<bool>>

Read as Vec<bool> from an array. Mirrors RenderedValue::as_bool_array.

Source

pub fn raw(&self) -> Option<&'a RenderedValue>

Drop into the raw RenderedValue for direct RenderedValue::member / RenderedValue::get / RenderedValue::index navigation. Use when the pattern-matched-into-known-shape access pattern (Option- returning terminals, no rich error context) reads more naturally than the SnapshotField’s Result-propagating chain. None for SnapshotField::PercpuKey (no underlying tree) and SnapshotField::Missing.

Source

pub fn iter_members(&self) -> impl Iterator<Item = SnapshotField<'a>> + '_

Iterate the elements of an array-shaped field as SnapshotFields so chained navigation composes: field.iter_members().filter_map(|el| el.get("name").as_u64().ok()). Bridges the gap left by the scalar as_*_array terminals on array-of-struct shapes: those terminals coerce each element to a scalar via the shared coercion helper and return SnapshotError::TypeMismatch on the first non-scalar element, which is exactly what an array-of-struct triggers. iter_members instead hands the caller each raw element so they can chain .get(field).as_u64() per element. Peels RenderedValue::Ptr dereferences and RenderedValue::Truncated partial-array wrappers the same way Self::as_u64_array does.

Yields nothing for non-array shapes, percpu-key fields, or missing fields — the empty iterator pattern is the natural “no elements to walk” representation when the chain just wants to fold over what’s there. iter_members itself never surfaces SnapshotError::TypeMismatch; callers needing to distinguish “absent” from “empty” check Self::is_present or Self::error explicitly.

Source

pub fn error(&self) -> Option<&SnapshotError>

Error reference when the field is missing; None otherwise.

Trait Implementations§

Source§

impl<'a> Debug for SnapshotField<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SnapshotField<'a>

§

impl<'a> RefUnwindSafe for SnapshotField<'a>

§

impl<'a> Send for SnapshotField<'a>

§

impl<'a> Sync for SnapshotField<'a>

§

impl<'a> Unpin for SnapshotField<'a>

§

impl<'a> UnwindSafe for SnapshotField<'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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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

§

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