Struct tor_util::RustString [] [src]

#[repr(C)]
pub struct RustString(_);

Compatibility wrapper for strings allocated in Rust and passed to C.

Rust doesn't ensure the safety of freeing memory across an FFI boundary, so we need to take special care to ensure we're not accidentally calling tor_free() on any string allocated in Rust. To more easily differentiate between strings that possibly (if Rust support is enabled) were allocated in Rust, C has the rust_str_t helper type. The equivalent on the Rust side is RustString.

Note: This type must not be used for strings allocated in C.

Methods

impl RustString
[src]

Returns a pointer to the underlying NUL-terminated byte array.

Note that this function is not typically useful for Rust callers, except in a direct FFI context.

Examples

use std::ffi::CString;

let r = RustString::from(CString::new("asdf").unwrap());
let c_str = r.as_ptr();
assert_eq!(b'a', unsafe { *c_str as u8});

Trait Implementations

impl Debug for RustString
[src]

Formats the value using the given formatter.

impl From<CString> for RustString
[src]

Constructs a new RustString

Examples

use std::ffi::CString;

let r = RustString::from(CString::new("asdf").unwrap());

impl Into<CString> for RustString
[src]

Reconstructs a CString from this RustString.

Useful to take ownership back from a RustString that was given to C code.

Examples

use std::ffi::CString;

let cs = CString::new("asdf").unwrap();
let r = RustString::from(cs.clone());
let cs2 = r.into();
assert_eq!(cs, cs2);

impl Drop for RustString
[src]

A method called when the value goes out of scope. Read more