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

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

#2324 in Rust patterns

Download history 5781/week @ 2025-10-09 6146/week @ 2025-10-16 6067/week @ 2025-10-23 6567/week @ 2025-10-30 7524/week @ 2025-11-06 6253/week @ 2025-11-13 6428/week @ 2025-11-20 5185/week @ 2025-11-27 5467/week @ 2025-12-04 5472/week @ 2025-12-11 4841/week @ 2025-12-18 3696/week @ 2025-12-25 4892/week @ 2026-01-01 6854/week @ 2026-01-08 6092/week @ 2026-01-15 5195/week @ 2026-01-22

23,649 downloads per month
Used in 20 crates (13 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

~135–520KB
~12K SLoC