Enum insta::internals::Content [−][src]
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)
I8(i8)
I16(i16)
I32(i32)
I64(i64)
F32(f32)
F64(f64)
Char(char)
String(String)
Implementations
impl Content
[src]
pub fn resolve_inner(&self) -> &Content
[src]
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.
pub fn as_str(&self) -> Option<&str>
[src]
Returns the value as string
pub fn as_bytes(&self) -> Option<&[u8]>
[src]
Returns the value as bytes
pub fn as_slice(&self) -> Option<&[Content]>
[src]
Returns the value as slice of content values.
pub fn is_nil(&self) -> bool
[src]
Returns true if the value is nil.
pub fn as_bool(&self) -> Option<bool>
[src]
Returns the value as bool
pub fn as_u64(&self) -> Option<u64>
[src]
Returns the value as u64
pub fn as_i64(&self) -> Option<i64>
[src]
Returns the value as i64
pub fn as_f64(&self) -> Option<f64>
[src]
Returns the value as f64
pub fn walk<F: FnMut(&mut Content) -> bool>(&mut self, visit: &mut F)
[src]
Recursively walks the content structure mutably.
The callback is invoked for every content in the tree.
Trait Implementations
impl Clone for Content
[src]
impl Debug for Content
[src]
impl<'a> From<&'a [u8]> for Content
[src]
impl<'a> From<&'a str> for Content
[src]
impl From<()> for Content
[src]
impl From<String> for Content
[src]
impl From<Vec<u8, Global>> for Content
[src]
impl From<bool> for Content
[src]
impl From<char> for Content
[src]
impl From<f32> for Content
[src]
impl From<f64> for Content
[src]
impl From<i16> for Content
[src]
impl From<i32> for Content
[src]
impl From<i64> for Content
[src]
impl From<i8> for Content
[src]
impl From<u16> for Content
[src]
impl From<u32> for Content
[src]
impl From<u64> for Content
[src]
impl From<u8> for Content
[src]
impl Serialize for Content
[src]
Auto Trait Implementations
impl RefUnwindSafe for Content
[src]
impl Send for Content
[src]
impl Sync for Content
[src]
impl Unpin for Content
[src]
impl UnwindSafe for Content
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,