2 releases

0.1.1 Feb 18, 2019
0.1.0 Feb 16, 2019

#13 in #safer

Download history 16/week @ 2024-01-07 16/week @ 2024-01-14 1/week @ 2024-01-28 1/week @ 2024-02-04 6/week @ 2024-02-11 24/week @ 2024-02-18 58/week @ 2024-02-25 8/week @ 2024-03-03 16/week @ 2024-03-10 23/week @ 2024-03-17 13/week @ 2024-03-24 68/week @ 2024-03-31 42/week @ 2024-04-07 16/week @ 2024-04-14 14/week @ 2024-04-21

141 downloads per month

MIT license

25KB
678 lines

::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!"));
}

Dependencies

~2MB
~45K SLoC