pub auto trait StackOnly { }
Expand description
Types which contain no pointers or references and can thus live entirely on the stack.
This trait is automatically implemented when the compiler determines it’s appropriate.
Note that this trait is sealed, i.e. you cannot implement it on your own custom types.
Primitive types like u8
and structs, tuples, and enums made only
from them implement StackOnly
.
In contrast, &T
, &mut T
, *const T
, *mut T
, and any type
containing a reference or a pointer do not implement StackOnly
.
§Examples
fn assert_stackonly(_x: impl StackOnly) {}
assert_stackonly(42); // ok
assert_stackonly([42; 42]); // ok
ⓘ
assert_stackonly(vec![42]); // error
ⓘ
assert_stackonly(&42); // error
ⓘ
assert_stackonly(ThreadBlockShared::new_uninit()); // error
ⓘ
assert_stackonly(ThreadBlockSharedSlice::new_uninit_with_len(0)); // error