Crate byte_strings

Source
Expand description

§::byte-strings

Rust zero-cost byte strings manipulation, for a better and safer FFI

Repository Latest version Documentation MSRV License CI

§Example

Featuring the c_str! macro to create valid C string literals with literally no runtime cost!

#[macro_use]
extern crate byte_strings;

/// Some lib
mod safe {
    use ::std::{
        ffi::CStr,
        os::raw::{c_char, c_int},
    };

    /// private unsafe C FFI
    mod ffi {
        use super::*;

        extern "C" {
            pub
            fn puts (_: *const c_char)
              -> c_int
            ;
        }
    }

    /// lib API: safe Rust wrapper => uses `CStr`
    pub
    fn puts (message: &'_ CStr)
      -> i32
    {
        unsafe {
            ffi::puts(message.as_ptr()) as i32
        }
    }
}

fn main ()
{
    safe::puts(c!("Hello, World!"));
}

Modules§

const_
const-friendly equivalents of the top-level crates.

Macros§

as_bytes
Concatenates (byte) string literals into a single byte string literal.
c
Shorthand alias. Converts into a valid [C string] at compile time (no runtime cost)
c_str
Converts into a valid [C string] at compile time (no runtime cost)
concat_bytes
Concatenates (byte) string literals into a single byte string literal.
const_as_bytes
const-friendly version of as_bytes!.
const_concat
const-friendly version of concat!.
const_concat_bytes
const-friendly version of concat_bytes!.
const_cstr
const-friendly version of c_str!.