6 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

#19 in #c-str

Download history 2840/week @ 2025-09-18 3259/week @ 2025-09-25 3102/week @ 2025-10-02 6839/week @ 2025-10-09 6918/week @ 2025-10-16 7126/week @ 2025-10-23 7381/week @ 2025-10-30 8335/week @ 2025-11-06 7022/week @ 2025-11-13 7892/week @ 2025-11-20 7339/week @ 2025-11-27 7269/week @ 2025-12-04 6633/week @ 2025-12-11 6648/week @ 2025-12-18 4956/week @ 2025-12-25 6053/week @ 2026-01-01

25,597 downloads per month
Used in 31 crates (2 directly)

Zlib OR MIT OR Apache-2.0

8KB
173 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

~155–560KB
~13K SLoC