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