#c-ffi #api-bindings #char #c-str

byte-strings

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

8 releases

0.3.1 Jun 12, 2023
0.3.0 Jun 12, 2023
0.2.2 Dec 10, 2021
0.2.1 Oct 28, 2021
0.1.3 Feb 20, 2019

#2474 in Rust patterns

Download history 2080/week @ 2025-05-23 1769/week @ 2025-05-30 1717/week @ 2025-06-06 1490/week @ 2025-06-13 2105/week @ 2025-06-20 1608/week @ 2025-06-27 1909/week @ 2025-07-04 2444/week @ 2025-07-11 2192/week @ 2025-07-18 2169/week @ 2025-07-25 1848/week @ 2025-08-01 1741/week @ 2025-08-08 1888/week @ 2025-08-15 1885/week @ 2025-08-22 2144/week @ 2025-08-29 2048/week @ 2025-09-05

8,235 downloads per month
Used in 15 crates (11 directly)

Zlib OR MIT OR Apache-2.0

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

~185–610KB
~15K SLoC