rokdocs
v0.1

rok::bare::ffi

rok::bare::ffi - NUL-terminated C strings (stdlib 1.7.2); wit is what the WIT bindings run on (1.8).

CStr and CString keep their bytes, NUL included, in one str object, so as_ptr holds as str::as_ptr does (2.15.2). CStr::from_ptr copies.

Modules

  • wit rok::bare::ffi::wit - what the generated WIT bindings run on (stdlib 1.8): linear-memory access at canonical ABI addresses (`i32`), the blocks strings and lists lower into, resource handles and `error-context`.

Structs

NulError

pub struct NulError

An interior NUL byte, at position (CString::new).

  • pub position: usize
Trait implementations 3
  • impl Display for NulError
  • impl Debug for NulError
  • impl Error for NulError

FromBytesWithNulError

pub struct FromBytesWithNulError

Bytes that are not one C string: no final NUL, or one before it.

  • pub reason: str
Trait implementations 3
  • impl Display for FromBytesWithNulError
  • impl Debug for FromBytesWithNulError
  • impl Error for FromBytesWithNulError

CStr

pub struct CStr

A NUL-terminated string (1.7.2).

  • pub fn from_ptr(p: ConstPtr<c_char>) -> CStr | none

    The C string at p (copied in); none for a null pointer. Without a NUL terminator the behavior is undefined.

  • pub const fn from_bytes_with_nul(bytes: Slice<u8>) throws (FromBytesWithNulError) -> CStr

    bytes when the last one is the only NUL.

  • pub const fn from_bytes_with_nul_unchecked(bytes: Slice<u8>) -> CStr

    bytes, whose last byte must be the only NUL (not checked).

  • pub fn as_ptr(self) -> ConstPtr<c_char>
  • pub fn as_bytes(self) -> Slice<u8>

    The bytes without the NUL.

  • pub fn as_bytes_with_nul(self) -> Slice<u8>
  • pub fn to_str(self) throws (Utf8Error) -> str
  • pub const fn len(self) -> usize

    Bytes before the NUL.

CString

pub struct CString

An owned NUL-terminated string (1.7.2).

  • pub const fn new(bytes: Slice<u8>) throws (NulError) -> CString

    bytes and a NUL; throws if bytes has a NUL of its own.

  • pub fn from_str(s: str) throws (NulError) -> CString
  • pub const fn as_c_str(self) -> CStr
  • pub fn as_ptr(self) -> ConstPtr<c_char>
  • pub fn into_bytes(self) -> List<u8>

    The bytes without the NUL.

  • pub fn into_bytes_with_nul(self) -> List<u8>