#[doc(hidden)] pub trait SizedTypeProperties: Sized {
#[doc(hidden)] const IS_ZST: bool = _;
#[doc(hidden)] const LAYOUT: Layout = _;
#[doc(hidden)] const MAX_SLICE_LEN: usize = _;
}
🔬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§
Source#[doc(hidden)] const IS_ZST: bool = _
🔬This is a nightly-only experimental API. (sized_type_properties
)
#[doc(hidden)] const IS_ZST: bool = _
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);
#[doc(hidden)] const LAYOUT: Layout = _
🔬This is a nightly-only experimental API. (
sized_type_properties
)Source#[doc(hidden)] const MAX_SLICE_LEN: usize = _
🔬This is a nightly-only experimental API. (sized_type_properties
)
#[doc(hidden)] const MAX_SLICE_LEN: usize = _
sized_type_properties
)The largest safe length for a [Self]
.
Anything larger than this would make size_of_val
overflow isize::MAX
,
which is never allowed for a single object.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.