docs

bare::ffi

本页内容

API 参考只有英文版,由标准库源代码中的英文文档注释生成。

C's types (types, also in the prelude), errno (errno), Nabi values C holds (handle), NUL-terminated C strings (wide: wchar_t ones), loading shared libraries (library); wit is what the WIT bindings run on; objc, Objective-C objects, exists only on Apple targets.

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

Modules

  • errno the C library's errno and Windows' GetLastError as the last #[errno] call left them.
  • handle Nabi values C code holds as a void*.
  • library shared libraries loaded at run time: dlopen on Unix, LoadLibraryW on Windows.
  • objc Objective-C objects on Apple targets.
  • types C's integer and float types under their C names, as the target's C compiler sizes them.
  • wide NUL-terminated wchar_t strings: UTF-16 on Windows (the W APIs), one unit per char (UTF-32) elsewhere.
  • wit what the generated WIT bindings run on: linear-memory access at canonical ABI addresses (i32), the blocks strings and lists lower into, resource handles and error-context.

Re-exports

errno::{errno, last_error, set_errno, set_last_error}Source

pub use errno::{errno, last_error, set_errno, set_last_error}
  • errno errno as the last #[errno] call on this thread left it.
  • last_error Windows' GetLastError as the last #[errno] call on this thread left it; 0 elsewhere.
  • set_errno Set errno, both the saved value and the C library's (for C functions that only report errors through it, such as strtol: set 0 first).
  • set_last_error Set the saved GetLastError value and, on Windows, the thread's own (SetLastError).

handle::HandleSource

pub use handle::Handle
  • Handle A Nabi value of type T that C holds as a void*.

library::{Library, LoadError, SymbolError}Source

pub use library::{Library, LoadError, SymbolError}
  • Library A loaded shared library, or the program itself (Library::this).
  • LoadError
  • SymbolError A library has no symbol of that name (Library::symbol).

wide::{WideCStr, WideCString}Source

pub use wide::{WideCStr, WideCString}

Structs

NulErrorSource

pub struct NulError
  • pub const fn position(self) -> usize§

    Source

    The byte offset of the NUL (from WideCString::new, its unit index).

  • pub const fn message(self) -> str§

    Source

    What went wrong, for display.

Trait implementations 6
  • impl PartialEq for NulError
  • impl Eq for NulError
  • impl Clone for NulError
  • impl Display for NulError
  • impl Debug for NulError
  • impl Error for NulError

FromBytesUntilNulErrorSource

pub struct FromBytesUntilNulError

Bytes with no NUL at all (CStr::from_bytes_until_nul).

  • pub const fn message(self) -> str§

    Source

    What went wrong, for display.

Trait implementations 6
  • impl PartialEq for FromBytesUntilNulError
  • impl Eq for FromBytesUntilNulError
  • impl Clone for FromBytesUntilNulError
  • impl Display for FromBytesUntilNulError
  • impl Debug for FromBytesUntilNulError
  • impl Error for FromBytesUntilNulError

CStrSource

pub struct CStr

A NUL-terminated string.

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

    Source

    The C string at p, copied up to its NUL; none for a null pointer.

    Safety: p must be null or point at a live NUL-terminated string.

  • pub const fn from_bytes_with_nul<B: AsBytes>(bytes: B) throws (FromBytesWithNulError) -> CStr§

    Source

    bytes when the last one is the only NUL.

  • pub const fn from_bytes_until_nul<B: AsBytes>(bytes: B) throws (FromBytesUntilNulError) -> CStr§

    Source

    The bytes up to the first NUL, which must be there; the rest is ignored (a fixed-size C buffer).

  • pub fn as_ptr(self) -> ConstPtr<c_char>§

    Source

    A pointer to the first byte, for C; valid while self is alive.

  • pub fn as_bytes(self) -> Slice<u8>§

    Source

    The bytes without the NUL.

  • pub fn as_bytes_with_nul(self) -> Slice<u8>§

    Source

    The bytes with the trailing NUL.

  • pub fn to_str(self) throws (Utf8Error) -> str§

    Source

    The bytes before the NUL as a str; throws if they are not UTF-8.

  • pub const fn len(self) -> usize§

    Source

    Bytes before the NUL.

Trait implementations 5

CStringSource

pub struct CString

An owned NUL-terminated string.

  • pub const fn new<B: AsBytes>(bytes: B) throws (NulError) -> CString§

    Source

    bytes and a NUL; throws if bytes has a NUL of its own. A str gives its UTF-8.

  • pub const fn as_c_str(self) -> CStr§

    Source

    The borrowed C string (with its NUL), valid while self is alive.

  • pub fn as_ptr(self) -> ConstPtr<c_char>§

    Source

    A pointer to the first byte, for C; valid while self is alive.

  • pub fn into_bytes(self) -> List<u8>§

    Source

    The bytes without the NUL.

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

    Source

    The bytes with the trailing NUL.

Trait implementations 5

Enums

FromBytesWithNulErrorSource

pub enum FromBytesWithNulError

Bytes that are not one C string (CStr::from_bytes_with_nul).

  • InteriorNul§

    Source

    A NUL before the last byte, at position.

  • NotNulTerminated§

    Source

    The last byte is not a NUL (or there is none).

  • pub const fn message(self) -> str§

    Source

    What went wrong, for display.

Trait implementations 6
  • impl PartialEq for FromBytesWithNulError
  • impl Eq for FromBytesWithNulError
  • impl Clone for FromBytesWithNulError
  • impl Display for FromBytesWithNulError
  • impl Debug for FromBytesWithNulError
  • impl Error for FromBytesWithNulError