Trait hacspec_lib::prelude::Debug

1.0.0 · source · []
pub trait Debug {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>;
}
Expand description

? formatting.

Debug should format the output in a programmer-facing, debugging context.

Generally speaking, you should just derive a Debug implementation.

When used with the alternate format specifier #?, the output is pretty-printed.

For more information on formatters, see the module-level documentation.

This trait can be used with #[derive] if all fields implement Debug. When derived for structs, it will use the name of the struct, then {, then a comma-separated list of each field’s name and Debug value, then }. For enums, it will use the name of the variant and, if applicable, (, then the Debug values of the fields, then ).

Stability

Derived Debug formats are not stable, and so may change with future Rust versions. Additionally, Debug implementations of types provided by the standard library (libstd, libcore, liballoc, etc.) are not stable, and may also change with future Rust versions.

Examples

Deriving an implementation:

#[derive(Debug)]
struct Point {
    x: i32,
    y: i32,
}

let origin = Point { x: 0, y: 0 };

assert_eq!(format!("The origin is: {origin:?}"), "The origin is: Point { x: 0, y: 0 }");

Manually implementing:

use std::fmt;

struct Point {
    x: i32,
    y: i32,
}

impl fmt::Debug for Point {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Point")
         .field("x", &self.x)
         .field("y", &self.y)
         .finish()
    }
}

let origin = Point { x: 0, y: 0 };

assert_eq!(format!("The origin is: {origin:?}"), "The origin is: Point { x: 0, y: 0 }");

There are a number of helper methods on the Formatter struct to help you with manual implementations, such as debug_struct.

Types that do not wish to use the standard suite of debug representations provided by the Formatter trait (debug_struct, debug_tuple, debug_list, debug_set, debug_map) can do something totally custom by manually writing an arbitrary representation to the Formatter.

impl fmt::Debug for Point {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "Point [{} {}]", self.x, self.y)
    }
}

Debug implementations using either derive or the debug builder API on Formatter support pretty-printing using the alternate flag: {:#?}.

Pretty-printing with #?:

#[derive(Debug)]
struct Point {
    x: i32,
    y: i32,
}

let origin = Point { x: 0, y: 0 };

assert_eq!(format!("The origin is: {origin:#?}"),
"The origin is: Point {
    x: 0,
    y: 0,
}");

Required Methods

Formats the value using the given formatter.

Examples
use std::fmt;

struct Position {
    longitude: f32,
    latitude: f32,
}

impl fmt::Debug for Position {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_tuple("")
         .field(&self.longitude)
         .field(&self.latitude)
         .finish()
    }
}

let position = Position { longitude: 1.987, latitude: 2.983 };
assert_eq!(format!("{position:?}"), "(1.987, 2.983)");

assert_eq!(format!("{position:#?}"), "(
    1.987,
    2.983,
)");

Implementors

Warning: declassifies secret integer types.

Warning: declassifies secret integer types.

Warning: declassifies secret integer types.

Warning: declassifies secret integer types.

This trait is implemented for tuples up to twelve items long.

impl Debug for Error

impl Debug for Prefix

impl Debug for Infix

impl Debug for Suffix

impl Debug for Colour

impl<'a, S: Debug + 'a + ToOwned + ?Sized> Debug for ANSIGenericString<'a, S> where
    <S as ToOwned>::Owned: Debug

impl<'a, S: Debug + 'a + ToOwned + ?Sized> Debug for ANSIGenericStrings<'a, S> where
    <S as ToOwned>::Owned: Debug,
    S: PartialEq

impl Debug for Style

impl<T: Debug, N> Debug for GenericArray<T, N> where
    N: ArrayLength<T>, 

impl<T: Debug, N> Debug for GenericArrayIter<T, N> where
    N: ArrayLength<T>, 

impl Debug for Error

impl Debug for State

impl Debug for Constants

impl Debug for Block

impl Debug for ChaChaIV

impl Debug for ChaChaKey

impl Debug for Error

impl Debug for PolyKey

impl Debug for PolyBlock

impl Debug for State

impl Debug for Row

impl Debug for Digest224

impl Debug for Digest256

impl Debug for Digest384

impl Debug for Digest512

impl Debug for Signature

impl Debug for DelimSpan

impl Debug for LineColumn

impl Debug for LexError

impl Debug for Span

impl Debug for TokenTree

impl Debug for Delimiter

impl Debug for Group

impl Debug for Spacing

impl Debug for Punct

impl Debug for Ident

impl Debug for Literal

impl Debug for IntoIter

impl Debug for Bernoulli

impl<D: Debug, R: Debug, T: Debug> Debug for DistIter<D, R, T>

impl<D: Debug, F: Debug, T: Debug, S: Debug> Debug for DistMap<D, F, T, S>

impl Debug for Open01

impl<'a, T: Debug> Debug for Slice<'a, T>

impl<X: Debug + SampleUniform + PartialOrd> Debug for WeightedIndex<X> where
    X::Sampler: Debug

impl<X: Debug + SampleUniform> Debug for Uniform<X> where
    X::Sampler: Debug

impl<X: Debug> Debug for UniformInt<X>

impl<X: Debug> Debug for UniformFloat<X>

impl<W: Debug + Weight> Debug for WeightedIndex<W>

impl Debug for Standard

impl<R: Debug> Debug for ReadRng<R>

impl Debug for ReadError

impl<R: Debug, Rsdr: Debug> Debug for ReseedingRng<R, Rsdr> where
    R: BlockRngCore + SeedableRng,
    Rsdr: RngCore

impl Debug for StepRng

impl Debug for StdRng

impl Debug for ThreadRng

impl Debug for IndexVec

impl<'a> Debug for IndexVecIter<'a>

impl<'a, S: Debug + ?Sized + 'a, T: Debug + 'a> Debug for SliceChooseIter<'a, S, T>

impl Debug for ChaCha8Rng

impl<R: BlockRngCore + Debug> Debug for BlockRng<R>

impl<R: BlockRngCore + Debug> Debug for BlockRng64<R>

impl Debug for Error

impl Debug for OsRng

impl Debug for Error

impl<E> Debug for UnitDeserializer<E>

impl<E> Debug for BoolDeserializer<E>

impl<E> Debug for I8Deserializer<E>

impl<E> Debug for I16Deserializer<E>

impl<E> Debug for I32Deserializer<E>

impl<E> Debug for I64Deserializer<E>

impl<E> Debug for IsizeDeserializer<E>

impl<E> Debug for U8Deserializer<E>

impl<E> Debug for U16Deserializer<E>

impl<E> Debug for U64Deserializer<E>

impl<E> Debug for UsizeDeserializer<E>

impl<E> Debug for F32Deserializer<E>

impl<E> Debug for F64Deserializer<E>

impl<E> Debug for CharDeserializer<E>

impl<E> Debug for I128Deserializer<E>

impl<E> Debug for U128Deserializer<E>

impl<E> Debug for U32Deserializer<E>

impl<'a, E> Debug for StrDeserializer<'a, E>

impl<'de, E> Debug for BorrowedStrDeserializer<'de, E>

impl<E> Debug for StringDeserializer<E>

impl<'a, E> Debug for CowStrDeserializer<'a, E>

impl<'a, E> Debug for BytesDeserializer<'a, E>

impl<'de, E> Debug for BorrowedBytesDeserializer<'de, E>

impl<I, E> Debug for SeqDeserializer<I, E> where
    I: Debug

impl<'de, I, E> Debug for MapDeserializer<'de, I, E> where
    I: Iterator + Debug,
    I::Item: Pair,
    <I::Item as Pair>::Second: Debug

impl Debug for IgnoredAny

impl<'a> Debug for Unexpected<'a>

impl Debug for Category

impl Debug for Error

impl Debug for Map<String, Value>

impl<'a> Debug for PrettyFormatter<'a>

impl Debug for Value

impl Debug for Number

impl<'a> Debug for ParseBuffer<'a>

impl Debug for Error

impl Debug for B0

impl Debug for B1

impl<U: Debug + Unsigned + NonZero> Debug for PInt<U>

impl<U: Debug + Unsigned + NonZero> Debug for NInt<U>

impl Debug for Z0

impl Debug for UTerm

impl<U: Debug, B: Debug> Debug for UInt<U, B>

impl Debug for ATerm

impl<V: Debug, A: Debug> Debug for TArr<V, A>

impl Debug for Greater

impl Debug for Less

impl Debug for Equal

impl Debug for Block

impl Debug for Word

impl Debug for RoundKey

impl Debug for Nonce

impl Debug for SBox

impl Debug for RCon

impl Debug for Bytes144

impl Debug for Bytes176

impl Debug for Bytes208

impl Debug for Bytes240

impl Debug for Key128

impl Debug for Key256

impl Debug for Block

impl Debug for Key

impl Debug for Tag

impl Debug for DigestB

impl Debug for Sigma

impl<T: Numeric + Copy> Debug for State<T>

impl<T: Numeric + Copy> Debug for DoubleState<T>

impl<T: Numeric + Copy> Debug for Counter<T>

impl Debug for Scalar

impl Debug for Scalar

impl Debug for Scalar

impl Debug for Block

impl Debug for Digest

impl Debug for Hash