Expand description
isit is a compile time checking library. It has a multitude of functions for performing compile time checks to
ensure that your program will work as expected before you ever run it.
§Examples
§const_assert
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::const_assert(std::mem::offset_of!(Fred, bar) == 8);§const_assert_all
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::const_assert_all([
std::mem::size_of::<Fred>() == 24,
std::mem::offset_of!(Fred, foo) == 0,
std::mem::offset_of!(Fred, bar) == 8,
std::mem::offset_of!(Fred, baz) == 16,
]);§const_assert_any
#[repr(C)]
struct Fred {
foo: u32,
bar: usize,
baz: bool,
}
const _: () = isit::const_assert_any([
// 64-bit systems
std::mem::size_of::<Fred>() == 24,
// 32-bit systems
std::mem::size_of::<Fred>() == 12,
// 16-bit systems
std::mem::size_of::<Fred>() == 8,
]);§const_assert_none
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::const_assert_none([
// align is 8, so none of these will be true.
std::mem::align_of::<Fred>() == 1,
std::mem::align_of::<Fred>() == 2,
std::mem::align_of::<Fred>() == 4,
]);§assert_size
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_size::<Fred, 24>();§assert_not_size
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
// If the type were not `C` layout, and were instead `Rust`
// layout, the size would end up being 16 instead of 24, and
// this check would fail.
const _: () = isit::assert_not_size::<Fred, 16>();§assert_same_size
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_same_size::<Fred, [u64; 3]>();§assert_different_size
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
///
#[repr(C)]
struct NotFred {
bar: u64,
foo: u32,
baz: bool,
}
const _: () = isit::assert_different_size::<Fred, NotFred>();§assert_compatible_size
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_compatible_size::<[u64; 1], Fred>();
const _: () = isit::assert_compatible_size::<[u64; 2], Fred>();
const _: () = isit::assert_compatible_size::<[u64; 3], Fred>();§assert_incompatible_size
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_incompatible_size::<Fred, [u64; 2]>();§assert_align
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_align::<Fred, 8>();§assert_not_align
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_not_align::<Fred, 4>();
const _: () = isit::assert_not_align::<Fred, 16>();§assert_same_align
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_same_align::<Fred, u64>();§assert_different_align
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_different_align::<Fred, u32>();
const _: () = isit::assert_different_align::<Fred, bool>();§assert_compatible_align
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_compatible_align::<Fred, u64>();§assert_incompatible_align
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_incompatible_align::<Fred, u32>();
const _: () = isit::assert_incompatible_align::<Fred, bool>();§assert_size_align
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_size_align::<Fred, 24, 8>();§assert_not_size_align
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_not_size_align::<Fred, 16, 4>();§assert_same_size_align
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_same_size_align::<Fred, [u64; 3]>();§assert_different_size_align
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_different_size_align::<Fred, [u32; 4]>();§assert_compatible_size_align
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_compatible_size_align::<[u32; 3], Fred>();§assert_incompatible_size_algin
#[repr(C)]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_incompatible_size_align::<Fred, u32>();§assert_pointer_size
use std::ptr::NonNull;
#[repr(transparent)]
struct Foo {
ptr: NonNull<u8>,
}
const _: () = isit::assert_pointer_size::<Foo>();§assert_not_pointer_size
#[repr(C)]
struct Foo {
a: bool,
b: u16,
c: bool,
d: u16,
e: bool,
}
const _: () = isit::assert_not_pointer_size::<Foo>();§assert_pointer_align
#[cfg_attr(target_pointer_width = "64", repr(C, align(8)))]
#[cfg_attr(target_pointer_width = "32", repr(C, align(4)))]
#[cfg_attr(target_pointer_width = "16", repr(C, align(2)))]
struct Foo(usize);
const _: () = isit::assert_pointer_align::<Foo>();§assert_not_pointer_align
#[repr(transparent)]
struct Foo {
inner: u8,
}
const _: () = isit::assert_not_pointer_align::<Foo>();§assert_pointer_size_align
use std::ptr::NonNull;
///
#[repr(transparent)]
struct Foo(NonNull<Foo>);
const _: () = isit::assert_pointer_size_align::<Foo>();§assert_not_pointer_size_align
#[repr(transparent)]
struct Foo(u8);
const _: () = isit::assert_not_pointer_size_align::<Foo>();§assert_pointer_compatible_size_align
#[repr(transparent)]
struct Foo(u8);
const _: () = isit::assert_pointer_compatible_size_align::<Foo>();§assert_pointer_incompatible_size_align
#[repr(C, align(16))]
struct Fred {
foo: u32,
bar: u64,
baz: bool,
}
const _: () = isit::assert_pointer_incompatible_size_align::<Fred>();§assert_t_niche
use std::ptr::NonNull;
///
#[repr(transparent)]
struct Foo {
ptr: NonNull<Foo>,
}
const _: () = isit::assert_t_niche::<Foo, NonNull<Foo>>();§assert_no_t_niche
#[repr(transparent)]
struct Foo {
foo: u32,
}
const _: () = isit::assert_no_t_niche::<Foo, u32>();§assert_t_niche_compatible
use std::num::NonZero;
#[repr(transparent)]
struct Foo(NonZero<u8>);
const _: () = isit::assert_t_niche_compatible::<Foo, NonZero<u8>>();
const _: () = isit::assert_t_niche_compatible::<Foo, NonZero<u16>>();§assert_niche
use std::ptr::NonNull;
///
#[repr(transparent)]
struct Foo(NonNull<Foo>);
const _: () = isit::assert_niche::<Foo>();§assert_no_niche
#[repr(transparent)]
struct Foo(u64);
const _: () = isit::assert_no_niche::<Foo>();§assert_single_niche
use std::ptr::NonNull;
///
#[repr(transparent)]
struct Foo(NonNull<Foo>);
const _: () = isit::assert_single_niche::<Foo>();§assert_pointer_niche
use std::ptr::NonNull;
///
#[repr(transparent)]
struct Foo(NonNull<Foo>);
const _: () = isit::assert_pointer_niche::<Foo>();§assert_no_pointer_niche
#[repr(transparent)]
struct Foo(usize);
const _: () = isit::assert_no_pointer_niche::<Foo>();§assert_pointer_niche_compatible
use std::num::NonZero;
#[repr(transparent)]
struct Foo(NonZero<u128>);
const _: () = isit::assert_pointer_niche_compatible::<Foo>();§assert_u8_niche
#[repr(u8)]
enum Fred {
Foo,
Bar,
Baz,
}
const _: () = isit::assert_u8_niche::<Fred>();§assert_u8_size_align
#[repr(transparent)]
struct Foo(u8);
const _: () = isit::assert_u8_size_align::<Foo>();§assert_u8_compatible
struct Zst;
#[repr(transparent)]
struct U8(u8);
const _: () = isit::assert_u8_compatible::<Zst>();
const _: () = isit::assert_u8_compatible::<U8>();§assert_u8_incompatible
#[repr(transparent)]
struct Foo(u16);
const _: () = isit::assert_u8_incompatible::<Foo>();§assert_zst
struct Zst;
const _: () = isit::assert_zst::<Zst>();
const _: () = isit::assert_zst::<()>();
const _: () = isit::assert_zst::<[[u64; u16::MAX as usize]; 0]>();§assert_not_zst
struct NonZst([u64; u16::MAX as usize]);
const _: () = isit::assert_not_zst::<NonZst>();§assert_uninhabited_zst
enum Uninhabited {}
struct Holder<T>(T);
const _: () = isit::assert_uninhabited_zst::<Uninhabited>();
const _: () = isit::assert_uninhabited_zst::<(Uninhabited, Uninhabited)>();
const _: () = isit::assert_uninhabited_zst::<[Uninhabited; usize::MAX]>();
const _: () = isit::assert_uninhabited_zst::<Holder<Uninhabited>>();
const _: () = isit::assert_uninhabited_zst::<Holder<[Uninhabited; usize::MAX]>>();
const _: () = isit::assert_uninhabited_zst::<Holder<[[Uninhabited; usize::MAX]; usize::MAX]>>();
const _: () = isit::assert_uninhabited_zst::<Holder<[[[Uninhabited; usize::MAX]; usize::MAX]; usize::MAX]>>();
const _: () = isit::assert_uninhabited_zst::<Holder<(
Holder<[[[Uninhabited; usize::MAX]; usize::MAX]; usize::MAX]>,
Holder<[[[Uninhabited; usize::MAX]; usize::MAX]; usize::MAX]>,
)>>();§assert_not_uninhabited_zst
struct Foo(u8);
const _: () = isit::assert_not_uninhabited_zst::<Foo>();Functions§
- align_
condition - Check that type
Thas alignment ofALIGNat compile time. - all_
condition - Check that all conditions are true at compile time.
- any_
condition - Check that any condition is
trueat compile time. - assert_
align - Assert that type
Thas alignment ofALIGNat compile time. - assert_
compatible_ align - Assert that type
Minhas an alignment that is less than or equal to the alignment of typeMaxat compile time. - assert_
compatible_ size - Assert that type
Minhas a size that is less than or equal to the size ofMaxat compile time. - assert_
compatible_ size_ align - Assert that the size and alignment of type
Minis less than or equal to the size and alignment of typeMaxat compile time. - assert_
different_ align - Assert that type
Lhas a different alignment than typeRat compile time. - assert_
different_ size - Assert that type
Land typeRhave different sizes at compile time. - assert_
different_ size_ align - Assert that type
Lhas a different size and alignment from typeRat compile time. - assert_
incompatible_ align - Assert that type
Maxhas an alignment that is greater than the alignment of typeMinat compile time. - assert_
incompatible_ size - Assert that type
Maxhas a size that is greater than the size of typeMinat compile time. - assert_
incompatible_ size_ align - Assert that size and alignment of type
Maxis greater than size and alignment of typeMinat compile time. - assert_
niche - Assert that type
Thas the same size and alignment asOption<T>at compile time. - assert_
no_ niche - Assert that type
Thas a different size fromOption<T>at compile time. - assert_
no_ pointer_ niche - Assert that
Option<T>has a size greater than a pointer at compile time. - assert_
no_ t_ niche - Check that
Option<Niched>has a greater size than typeTat compile time. - assert_
not_ align - Assert that type
Tdoes not have alignment ofALIGNat compile time. - assert_
not_ pointer_ align - Assert that type
Tis does not have the same alignment as a pointer at compile time. - assert_
not_ pointer_ size - Assert that type
Tis not the same size as a pointer at compile time. - assert_
not_ pointer_ size_ align - Assert that type
Thas a different size and alignment from a pointer at compile time. - assert_
not_ size - Assert that the size of
Tdoes not matchSIZEat compile time. - assert_
not_ size_ align - Assert that type
Thas either a different size thanSIZEand a different alignment thanALIGNat compile time. - assert_
not_ uninhabited_ zst - Assert that type
Tis not an uninhabited ZST (zero-sized type) at compile time. - assert_
not_ zst - Assert that type
Tis not a ZST (zero-sized type) at compile time. - assert_
pointer_ align - Assert that type
Thas the same alignment as a pointer at compile time. - assert_
pointer_ compatible_ size_ align - Assert that type
Thas a size and alignment that is less than or equal to the size and alignment of a pointer at compile time. - assert_
pointer_ incompatible_ size_ align - Assert that the size or alignment of type
Tis greater than the size or alignment of a pointer at compile time. - assert_
pointer_ niche - Assert that
Option<T>has the same size and alignment as a pointer at compile time. - assert_
pointer_ niche_ compatible - Assert that the size and alignment of
Option<T>is greater or equal to the size and alignment of a pointer at compile time. - assert_
pointer_ size - Assert that type
Thas the same size as a pointer at compile time. - assert_
pointer_ size_ align - Assert that type
Thas the same size and alignment as a pointer at compile time. - assert_
same_ align - Assert that type
Lhas the same alignment as typeRat compile time. - assert_
same_ size - Assert that type
Lis the same size as typeRat compile time. - assert_
same_ size_ align - Check that type
Lhas the same size and alignment as typeRat compile time. - assert_
single_ niche - Assert that type
Thas the same size and alignment asOption<T>, but has a different size thanOption<Option<T>>at compile time. - assert_
size - Assert that the size of
TmatchesSIZEat compile time. - assert_
size_ align - Assert that type
Thas the size ofSIZEand the alignment ofALIGNat compile time. - assert_
t_ niche - Assert that type
Thas the same size and alignment asOption<Niched>at compile time. - assert_
t_ niche_ compatible - Assert that the size and alignment of
Tis less than or equal to the size and alignment ofOption<Niched>at compile time. - assert_
u8_ compatible - Assert that type
Thas a size and alignment that is less or equal to the size and alignment ofu8at compile time. - assert_
u8_ incompatible - Assert that the size or alignment of
Tis greater than the size or alignment ofu8at compile time. - assert_
u8_ niche - Assert that the size of
Option<T>is equal to the size ofu8at compile time. - assert_
u8_ size_ align - Assert that type
Thas the same size and alignment as au8at compile time. - assert_
uninhabited_ zst - Assert that type
Tis an uninhabited ZST (zero-sized type) at compile time. - assert_
zst - Assert that type
Tis a ZST (zero-sized type) at compile time. - compatible_
align_ condition - Check that type
Minhas an alignment that is less than or equal to the alignment of typeMaxat compile time. - compatible_
size_ align_ condition - Check that the size and alignment of type
Minis less than or equal to the size and alignment of typeMaxat compile time. - compatible_
size_ condition - Check that type
Minhas a size that is less than or equal to the size ofMaxat compile time. - const_
assert - Assert that a condition is
trueat compile time. - const_
assert_ all - Assert that all conditions are
trueat compile time. - const_
assert_ any - Assert that any condition is
trueat compile time. - const_
assert_ none - Assert that none of the conditions are
trueat compile time. - different_
align_ condition - Check that type
Lhas a different alignment than typeRat compile time. - different_
size_ align_ condition - Check that type
Lhas a different size and alignment from typeRat compile time. - different_
size_ condition - Check that type
Land typeRhave different sizes at compile time. - incompatible_
align_ condition - Check that type
Maxhas an alignment that is greater than the alignment of typeMinat compile time. - incompatible_
size_ align_ condition - Check that size and alignment of type
Maxis greater than size and alignment of typeMinat compile time. - incompatible_
size_ condition - Check that type
Maxhas a size that is greater than the size of typeMinat compile time. - niche_
condition - Check that type
Thas the same size and alignment asOption<T>at compile time. - no_
niche_ condition - Check that type
Thas a different size fromOption<T>at compile time. - no_
pointer_ niche_ condition - Check that
Option<T>has a size greater than a pointer at compile time. - no_
t_ niche_ condition - Check that
Option<Niched>has a greater size than typeTat compile time. - none_
condition - Check that none of the conditions are
trueat compile time. - not_
align_ condition - Check that type
Tdoes not have the alignment ofALIGNat compile time. - not_
pointer_ align_ condition - Check that type
Tis does not have the same alignment as a pointer at compile time. - not_
pointer_ size_ align_ condition - Check that type
Thas a different size and alignment from a pointer at compile time. - not_
pointer_ size_ condition - Check that type
Tis not the same size as a pointer at compile time. - not_
size_ align_ condition - Check that type
Thas either a different size thanSIZEand a different alignment thanALIGNat compile time. - not_
size_ condition - Check that the size of
Tdoes not matchSIZEat compile time. - not_
uninhabited_ zst_ condition - Check that type
Tis not an uninhabited ZST (zero-sized type) at compile time. - not_
zst_ condition - Check that type
Tis not a ZST (zero-sized type) at compile time. - pointer_
align_ condition - Check that type
Thas the same alignment as a pointer at compile time. - pointer_
compatible_ size_ align_ condition - Check that type
Thas a size and alignment that is less than or equal to the size and alignment of a pointer at compile time. - pointer_
incompatible_ size_ align_ condition - Check that the size or alignment of type
Tis greater than the size or alignment of a pointer at compile time. - pointer_
niche_ compatible_ condition - Check that the size and alignment of
Option<T>is less or equal to the size and alignment of a pointer at compile time. - pointer_
niche_ condition - Check that
Option<T>has the same size and alignment as a pointer at compile time. - pointer_
size_ align_ condition - Check that type
Thas the same size and alignment as a pointer at compile time. - pointer_
size_ condition - Check that type
Thas the same size as a pointer at compile time. - same_
align_ condition - Check that type
Lhas the same alignment as typeRat compile time. - same_
size_ align_ condition - Check that type
Lhas the same size and alignment as typeRat compile time. - same_
size_ condition - Check that type
Lis the same size as typeRat compile time. - single_
niche_ condition - Check that type
Thas the same size and alignment asOption<T>, but has a different size thanOption<Option<T>>at compile time. - size_
align_ condition - Check that type
Thas the size ofSIZEand the alignment ofALIGNat compile time. - size_
condition - Check that the size of
TmatchesSIZEat compile time. - t_
niche_ compatible_ condition - Check that the size and alignment of
Tis less than or equal to the size and alignment ofOption<Niched>at compile time. - t_
niche_ condition - Checks that type
Thas the same size and alignment asOption<Niched>at compile time. - u8_
compatible_ condition - Check that type
Thas a size and alignment that is less or equal to the size and alignment ofu8at compile time. - u8_
incompatible_ condition - Check that the size or alignment of
Tis greater than the size or alignment ofu8at compile time. - u8_
niche_ condition - Check that the size of
Option<T>is equal to the size ofu8at compile time. - u8_
size_ align_ condition - Check that type
Thas the same size and alignment as au8at compile time. - uninhabited_
zst_ condition - Check that type
Tis an uninhabited ZST (zero-sized type) at compile time. - zst_
condition - Check that type
Tis a ZST (zero-sized type) at compile time.