Skip to main content

AsRust

Trait AsRust 

Source
pub trait AsRust<T> {
    // Required method
    fn as_rust(&self) -> Result<T, AsRustError>;
}
Expand description

Non-consuming conversion from a #[repr(C)] value back to an owned, idiomatic Rust value.

AsRust<U> takes &self and returns a freshly-allocated U, copying data out of any pointer field by borrowing through RawBorrow. The original C-compatible value is left untouched and its allocations are not freed; releasing them is the caller’s responsibility.

This is the recommended entry point for values handed to Rust by C — see the crate-level Philosophy.

Required Methods§

Source

fn as_rust(&self) -> Result<T, AsRustError>

Return a freshly-allocated Rust value equivalent to self.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl AsRust<String> for CStr

Source§

impl AsRust<bool> for bool

Source§

impl AsRust<f32> for f32

Source§

impl AsRust<f64> for f64

Source§

impl AsRust<i8> for i8

Source§

impl AsRust<i16> for i16

Source§

impl AsRust<i32> for i32

Source§

impl AsRust<i64> for i64

Source§

impl AsRust<u8> for u8

Source§

impl AsRust<u16> for u16

Source§

impl AsRust<u32> for u32

Source§

impl AsRust<u64> for u64

Source§

impl AsRust<usize> for i32

Source§

impl AsRust<usize> for usize

Source§

impl<U: AsRust<T>, T, const N: usize> AsRust<[T; N]> for [U; N]

Implementors§