#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

#374 in Rust patterns

Download history 541/week @ 2022-10-07 748/week @ 2022-10-14 1215/week @ 2022-10-21 1202/week @ 2022-10-28 1525/week @ 2022-11-04 1492/week @ 2022-11-11 1136/week @ 2022-11-18 1173/week @ 2022-11-25 1723/week @ 2022-12-02 1975/week @ 2022-12-09 1876/week @ 2022-12-16 853/week @ 2022-12-23 861/week @ 2022-12-30 1611/week @ 2023-01-06 1679/week @ 2023-01-13 2340/week @ 2023-01-20

6,720 downloads per month
Used in fewer than 6 crates

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

~195–590KB
~14K SLoC