#[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
Value(&'a RenderedValue)
Resolved rendered value at the leaf of the path walk.
PercpuKey
Dedicated per-CPU array key shape (u32, no struct).
Missing(SnapshotError)
Path could not be resolved.
Implementations§
Source§impl<'a> SnapshotField<'a>
impl<'a> SnapshotField<'a>
Sourcepub fn get(&self, path: &str) -> SnapshotField<'a>
pub fn get(&self, path: &str) -> SnapshotField<'a>
Walk into a sub-field. Composable with
super::SnapshotEntry::get.
Sourcepub fn is_present(&self) -> bool
pub fn is_present(&self) -> bool
True when the field resolved successfully.
Sourcepub fn as_u64(&self) -> SnapshotResult<u64>
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.
Sourcepub fn as_i64(&self) -> SnapshotResult<i64>
pub fn as_i64(&self) -> SnapshotResult<i64>
Read as i64.
Sourcepub fn as_bool(&self) -> SnapshotResult<bool>
pub fn as_bool(&self) -> SnapshotResult<bool>
Read as bool. RenderedValue::Bool direct, ints / enums
non-zero is true.
Sourcepub fn as_f64(&self) -> SnapshotResult<f64>
pub fn as_f64(&self) -> SnapshotResult<f64>
Read as f64.
Sourcepub fn as_str(&self) -> SnapshotResult<&'a str>
pub fn as_str(&self) -> SnapshotResult<&'a str>
Read the variant string for an RenderedValue::Enum with
a resolved variant name.
Sourcepub fn as_u64_array(&self) -> SnapshotResult<Vec<u64>>
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.
Sourcepub fn as_u32_array(&self) -> SnapshotResult<Vec<u32>>
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.
Sourcepub fn as_i64_array(&self) -> SnapshotResult<Vec<i64>>
pub fn as_i64_array(&self) -> SnapshotResult<Vec<i64>>
Read as Vec<i64> from an array. Mirrors
RenderedValue::as_i64_array.
Sourcepub fn as_f64_array(&self) -> SnapshotResult<Vec<f64>>
pub fn as_f64_array(&self) -> SnapshotResult<Vec<f64>>
Read as Vec<f64> from an array. Mirrors
RenderedValue::as_f64_array.
Sourcepub fn as_bool_array(&self) -> SnapshotResult<Vec<bool>>
pub fn as_bool_array(&self) -> SnapshotResult<Vec<bool>>
Read as Vec<bool> from an array. Mirrors
RenderedValue::as_bool_array.
Sourcepub fn raw(&self) -> Option<&'a RenderedValue>
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.
Sourcepub fn iter_members(&self) -> impl Iterator<Item = SnapshotField<'a>> + '_
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.
Sourcepub fn error(&self) -> Option<&SnapshotError>
pub fn error(&self) -> Option<&SnapshotError>
Error reference when the field is missing; None
otherwise.
Trait Implementations§
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> 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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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