Enum insta::internals::Content

source ·
pub enum Content {
Show 18 variants Bool(bool), U8(u8), U16(u16), U32(u32), U64(u64), U128(u128), I8(i8), I16(i16), I32(i32), I64(i64), I128(i128), F32(f32), F64(f64), Char(char), String(String), Bytes(Vec<u8>), Seq(Vec<Content>), Map(Vec<(Content, Content)>), // some variants omitted
}
Expand description

Represents variable typed content.

This is used for the serialization system to represent values before the actual snapshots are written and is also exposed to dynamic redaction functions.

Some enum variants are intentionally not exposed to user code. It’s generally recommended to construct content objects by using the From trait and by using the accessor methods to assert on it.

While matching on the content is possible in theory it is recommended against. The reason for this is that the content enum holds variants that can “wrap” values where it’s not expected. For instance if a field holds an Option<String> you cannot use pattern matching to extract the string as it will be contained in an internal Some variant that is not exposed. On the other hand the as_str method will automatically resolve such internal wrappers.

If you do need to pattern match you should use the resolve_inner method to resolve such internal wrappers.

Variants§

§

Bool(bool)

§

U8(u8)

§

U16(u16)

§

U32(u32)

§

U64(u64)

§

U128(u128)

§

I8(i8)

§

I16(i16)

§

I32(i32)

§

I64(i64)

§

I128(i128)

§

F32(f32)

§

F64(f64)

§

Char(char)

§

String(String)

§

Bytes(Vec<u8>)

§

Seq(Vec<Content>)

§

Map(Vec<(Content, Content)>)

Implementations§

source§

impl Content

source

pub fn resolve_inner(&self) -> &Content

This resolves the innermost content in a chain of wrapped content.

For instance if you encounter an Option<Option<String>> field the content will be wrapped twice in an internal option wrapper. If you need to pattern match you will need in some situations to first resolve the inner value before such matching can take place as there is no exposed way to match on these wrappers.

This method does not need to be called for the as_ methods which resolve automatically.

source

pub fn resolve_inner_mut(&mut self) -> &mut Content

Mutable version of resolve_inner.

source

pub fn as_str(&self) -> Option<&str>

Returns the value as string

source

pub fn as_bytes(&self) -> Option<&[u8]>

Returns the value as bytes

source

pub fn as_slice(&self) -> Option<&[Content]>

Returns the value as slice of content values.

source

pub fn is_nil(&self) -> bool

Returns true if the value is nil.

source

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

Returns the value as bool

source

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

Returns the value as u64

source

pub fn as_u128(&self) -> Option<u128>

Returns the value as u128

source

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

Returns the value as i64

source

pub fn as_i128(&self) -> Option<i128>

Returns the value as i128

source

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

Returns the value as f64

source

pub fn walk<F: FnMut(&mut Content) -> bool>(&mut self, visit: &mut F)

Recursively walks the content structure mutably.

The callback is invoked for every content in the tree.

Trait Implementations§

source§

impl Clone for Content

source§

fn clone(&self) -> Content

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 Content

source§

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

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

impl<'a> From<&'a [u8]> for Content

source§

fn from(value: &'a [u8]) -> Content

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for Content

source§

fn from(value: &'a str) -> Content

Converts to this type from the input type.
source§

impl From<()> for Content

source§

fn from(_value: ()) -> Content

Converts to this type from the input type.
source§

impl From<String> for Content

source§

fn from(value: String) -> Content

Converts to this type from the input type.
source§

impl From<Vec<u8>> for Content

source§

fn from(value: Vec<u8>) -> Content

Converts to this type from the input type.
source§

impl From<bool> for Content

source§

fn from(value: bool) -> Content

Converts to this type from the input type.
source§

impl From<char> for Content

source§

fn from(value: char) -> Content

Converts to this type from the input type.
source§

impl From<f32> for Content

source§

fn from(value: f32) -> Content

Converts to this type from the input type.
source§

impl From<f64> for Content

source§

fn from(value: f64) -> Content

Converts to this type from the input type.
source§

impl From<i128> for Content

source§

fn from(value: i128) -> Content

Converts to this type from the input type.
source§

impl From<i16> for Content

source§

fn from(value: i16) -> Content

Converts to this type from the input type.
source§

impl From<i32> for Content

source§

fn from(value: i32) -> Content

Converts to this type from the input type.
source§

impl From<i64> for Content

source§

fn from(value: i64) -> Content

Converts to this type from the input type.
source§

impl From<i8> for Content

source§

fn from(value: i8) -> Content

Converts to this type from the input type.
source§

impl From<u128> for Content

source§

fn from(value: u128) -> Content

Converts to this type from the input type.
source§

impl From<u16> for Content

source§

fn from(value: u16) -> Content

Converts to this type from the input type.
source§

impl From<u32> for Content

source§

fn from(value: u32) -> Content

Converts to this type from the input type.
source§

impl From<u64> for Content

source§

fn from(value: u64) -> Content

Converts to this type from the input type.
source§

impl From<u8> for Content

source§

fn from(value: u8) -> Content

Converts to this type from the input type.
source§

impl PartialEq for Content

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Content

source§

fn partial_cmp(&self, other: &Content) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Content

Available on crate feature serde only.
source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for Content

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> 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,

§

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>,

§

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>,

§

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.