Crates.io | size-trait |
lib.rs | size-trait |
version | 0.1.0 |
source | src |
created_at | 2023-07-21 06:10:21.100367 |
updated_at | 2023-07-21 06:10:21.100367 |
description | Traits for restricting the size of type parameters. |
homepage | |
repository | https://github.com/encody/size-trait |
max_upload_size | |
id | 922150 |
size | 49,290 |
This crate provides traits for restricting the size of type parameters.
#![feature(generic_const_exprs)]
use size_trait::ZeroSize;
// This struct can only contain `T` when `T` has a size of 0.
struct Zst<T: ZeroSize<true>>(T);
let _ = Zst([0u8; 0]);
let _ = Zst(());
#![feature(generic_const_exprs)]
use size_trait::Size;
// This struct can only contain `T` when `T` has a size of 4 bytes.
struct Fixed4Bytes<T: Size<4>>(T);
let _ = Fixed4Bytes([0u8; 4]);
let _ = Fixed4Bytes(0u32);
This crate relies on the unstable feature generic_const_exprs
. This feature is only available on nightly Rust. It is also not guaranteed to be stable in the future. Tracking issue #76560.
In order for this crate to work properly, you must enable the generic_const_exprs
feature in your crate:
#![feature(generic_const_exprs)]