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.

Examples
#![feature(sized_type_properties)]
use core::mem::SizedTypeProperties;

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

struct MyUnit;
assert!(MyUnit::IS_ZST);

// For negative checks, consider using UFCS to emphasize the negation
assert!(!<i32>::IS_ZST);
// As it can sometimes hide in the type otherwise
assert!(!String::IS_ZST);
Run

Implementors§