pub trait SizedTypeProperties: Sized {
    const IS_ZST: bool = _;
🔬This is a nightly-only experimental API. (sized_type_properties)
Expand description

Provides associated constants for various useful properties of types, to give them a canonical form in our code and make them easier to read.

This is here only to simplify all the ZST checks we need in the library. It’s not on a stabilization track right now.

Provided Associated Constants§

🔬This is a nightly-only experimental API. (sized_type_properties)

true if this type requires no storage. false if its size is greater than zero.

use core::mem::SizedTypeProperties;

fn do_something_with<T>() {
    if T::IS_ZST {
        // ... special approach ...
    } else {
        // ... the normal thing ...

struct MyUnit;

// For negative checks, consider using UFCS to emphasize the negation
// As it can sometimes hide in the type otherwise