Skip to main content

rust_spec/core_impls/
ffi.rs

1use core::ffi::{CStr, c_void};
2
3#[cfg(feature = "alloc")]
4use alloc::ffi::CString;
5
6#[cfg(feature = "alloc")]
7use crate::niche::WithNiche;
8use crate::{
9    RustSpec, Stable, Unstable,
10    layout::{NonRobust, Robust},
11    mutability::Exclusive,
12    niche::WithoutNiche,
13    size::{self, MetaSized, SliceLike},
14};
15
16unsafe impl RustSpec for c_void {
17    type Layout = Stable;
18    type Size = size::Sized<crate::Gt<crate::Zero>>;
19    type Alignment = crate::One;
20    type Trap = Robust;
21    type Niche = WithoutNiche;
22    type Mutability = Exclusive;
23    type __IndirectTrap = Robust;
24}
25
26unsafe impl RustSpec for CStr {
27    type Layout = Unstable;
28    type Size = MetaSized<SliceLike>;
29    type Alignment = crate::One;
30    type Trap = NonRobust;
31    type Niche = WithoutNiche;
32    type Mutability = Exclusive;
33    type __IndirectTrap = Robust;
34}
35
36#[cfg(feature = "alloc")]
37unsafe impl RustSpec for CString {
38    type Layout = Unstable;
39    type Size = size::Sized<crate::Gt<crate::Zero>>;
40    type Alignment = <usize as RustSpec>::Alignment;
41    type Trap = NonRobust;
42    type Niche = WithNiche<Unstable>;
43    type Mutability = Exclusive;
44    type __IndirectTrap = Robust;
45}