diff options
author | Isis Lovecruft <isis@torproject.org> | 2018-02-10 01:41:06 +0000 |
---|---|---|
committer | Isis Lovecruft <isis@torproject.org> | 2018-02-10 02:19:18 +0000 |
commit | 081e99c16f754ffd5605acdfddec527a2a426ed8 (patch) | |
tree | 583f8e480e9ace2842067584b2fcb499374f8f59 /src/rust/tor_util/strings.rs | |
parent | 6c77593a57d5a22a2fb3105d1466fb3ed26b1244 (diff) | |
download | tor-081e99c16f754ffd5605acdfddec527a2a426ed8.tar.gz tor-081e99c16f754ffd5605acdfddec527a2a426ed8.zip |
rust: Remove empty_static_cstr() in favour of new cstr!() macro.
Diffstat (limited to 'src/rust/tor_util/strings.rs')
-rw-r--r-- | src/rust/tor_util/strings.rs | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/src/rust/tor_util/strings.rs b/src/rust/tor_util/strings.rs index 659e792a34..dc4919d80f 100644 --- a/src/rust/tor_util/strings.rs +++ b/src/rust/tor_util/strings.rs @@ -3,8 +3,6 @@ //! Utilities for working with static strings. -use std::ffi::CStr; - /// A byte-array containing a single NUL byte (`b"\0"`). pub const NUL_BYTE: &'static [u8] = b"\0"; @@ -44,43 +42,6 @@ pub fn byte_slice_is_c_like(bytes: &[u8]) -> bool { false } -/// Get a static `CStr` containing a single `NUL_BYTE`. -/// -/// # Examples -/// -/// When used as follows in a Rust FFI function, which could be called -/// from C: -/// -/// ``` -/// # extern crate libc; -/// # extern crate tor_util; -/// # -/// # use tor_util::strings::empty_static_cstr; -/// use libc::c_char; -/// use std::ffi::CStr; -/// -/// pub extern "C" fn give_c_code_an_empty_static_string() -> *const c_char { -/// let empty: &'static CStr = empty_static_cstr(); -/// -/// empty.as_ptr() -/// } -/// -/// # fn main() { -/// # give_c_code_an_empty_static_string(); -/// # } -/// ``` -/// -/// This equates to an "empty" `const char*` static string in C. -pub fn empty_static_cstr() -> &'static CStr { - let empty: &'static CStr; - - unsafe { - empty = CStr::from_bytes_with_nul_unchecked(NUL_BYTE); - } - - empty -} - /// Create a `CStr` from a literal byte slice, appending a NUL byte to it first. /// /// # Warning |