#ffi #c #string #char #c-str

byte-strings

Rust byte strings manipulation, for a better and safer C FFI

6 releases

0.2.2 Dec 10, 2021
0.2.1 Oct 28, 2021
0.1.3 Feb 20, 2019

#420 in Rust patterns

Download history 161/week @ 2021-10-01 117/week @ 2021-10-08 151/week @ 2021-10-15 136/week @ 2021-10-22 82/week @ 2021-10-29 188/week @ 2021-11-05 302/week @ 2021-11-12 219/week @ 2021-11-19 280/week @ 2021-11-26 424/week @ 2021-12-03 523/week @ 2021-12-10 322/week @ 2021-12-17 196/week @ 2021-12-24 220/week @ 2021-12-31 311/week @ 2022-01-07 246/week @ 2022-01-14

1,043 downloads per month
Used in indymilter

Zlib OR MIT OR Apache-2.0

16KB
269 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

~285–700KB
~17K SLoC

R=a