Enum maybe_debug::MaybeDebug[][src]

#[non_exhaustive]
pub enum MaybeDebug<'a> {
    // some variants omitted
}
Expand description

Optional presense of Debug information (equivalent to Option<&dyn Debug>)

The main difference from the equivalent Option is that it prints a reasonable fallback (the type’s name).

In other words maybe_debug(NotDebug) gives "NotDebug { ... } instead of just printing None.

You can always retrieve the original type name of the value, regardless of whether the Debug implementation is Some or None.

The type name is the same one given by core::any::type_name.

The specific variants of this struct are considered an implementation detail.

Implementations

Check if this type contians an underlying Debug implementation.

Using the Option<&dyn Debug> analogy, this would be equivalent to is_some

Check if this type is using a fallback implementation (based on the type name) (ie !self.has_debug_info())

Note this returns true even for MaybeDebug::fallback_slice, despite the fact that does include length information.

Using the Option<&dyn Debug> analogy, this would be equivalent to is_none.

Check if this type is known to be a slice.

This function has false negatives, but no false positives.

For example, if MaybeDebug::fallback is used, then this function will return false even if fallback is given a slice.

If the original value was a slice, return its length.

Returns None if the original value was not known to be a slice.

Just like MaybeDebug::is_known_slice, this may have false negatives on whether or not something is a slice. However, if it returns Some, then the length is guarenteed to be correct.

Return the underling type name, as given by core::any::type_name

This function always succeeds.

Construct a “passthrough” ‘MaybeDebug’, that will simply delegate to the underlying implementation.

On nightly, this is equivalent to maybe_debug. However, on stable, maybe_debug cannot specialize and will unconditionally call MaybeDebug::fallback.

Therefore, this may be useful on stable rust if you need to create a ‘MaybeDebug’ value from a type that is unconditionally known to implement Debug.

Construct a “passthrough” MaybeDebug, that will simply delegate to str’s Debug implementation.

Note that a regular passthrough cannot work because str: !Sized

Construct a “passthrough” MaybeDebug that will simply Debug each individual value in the slice.

On nightly, this is equivalent to maybe_debug. However, on stable, maybe_debug cannot specialize and will unconditionally call MaybeDebug::fallback.

Even worse, it cannot even detect the fact the type is a slice.

NOTE (for stable only): Until RFC #2580 is stabilized, this function will unconditionally delegate to MaybeDebug::fallback_slice on the stable compiler. This is still better than maybe_debug (or a plain fallback), since it also prints the length. Users using nightly can ignore this warning.

See also MaybeDebug::passthrough and MaybeDebug::fallback_slice.

Unconditionally use the “fallback” implementation for the specified slice.

The current implementation simply prints the name and the slice length.

On stable this actually gives more information than maybe_debug. This is because maybe_debug cannot specialize to slices, so it simply prints the type name without any length information.

On nightly, this is strictly worse than maybe_debug, because it cannot specialize to the case that [T]: Debug.

A fallback implementation that unconditionally prints the type name.

For example fallback<Option<usize>>() would print "std::option::Option<usize> { ... }"

On stable, maybe_debug unconditionally delegates to this function. On nightly, this is used if T is !Debug (and isn’t a slice).

However on nightly, if T is Debug it is strictly worse than maybe_debug because it cannot take advantage of any Debug implementation for T.

There is really almost no scenario in which you want to use this function. core::any::type_name expresses the intent of printing the type name more clearly and maybe_debug is able to take advantage of specialization on the nightly compiler.

It is included only for completeness. NOTE: It doesn’t actually require a value for T, since it only uses its type name.

See also Self::fallback_slice which also prints length information (which may actually be useful)

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.