Skip to main content

FfiSafeErrorMessage

Trait FfiSafeErrorMessage 

Source
pub unsafe trait FfiSafeErrorMessage {
    // Required method
    fn as_ffi_str(&self) -> &'static CStr;

    // Provided method
    fn as_rust_str(&self) -> &'static str { ... }
}
Expand description

A trait to represent a static error message that is represented by both the requirements of Rust strings and C strings:

  1. It must be a null terminated string with no interior null bytes.
  2. It must be valid UTF-8.
  3. It must not allocate to achieve the static bounds.

Using a c-str literal in Rust achieves all these requirements:

c"this string is compatible with FfiSafeErrorMessage";

§Safety

The strings returned by as_ffi_str must be valid UTF-8.

Required Methods§

Source

fn as_ffi_str(&self) -> &'static CStr

Returns the error message as a static CStr. It must also be a valid Rust string, including being UTF-8.

Provided Methods§

Source

fn as_rust_str(&self) -> &'static str

Returns the error message as a static Rust str, excluding the null terminator. If you need it, use FfiSafeErrorMessage::as_ffi_str.

Do not override this method, it would be marked final if it existed.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§