#string-literal #string #c-str #c-strings #ffi #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

#1038 in Rust patterns

Download history 1788/week @ 2024-09-29 1067/week @ 2024-10-06 1298/week @ 2024-10-13 1770/week @ 2024-10-20 1676/week @ 2024-10-27 1259/week @ 2024-11-03 1464/week @ 2024-11-10 1685/week @ 2024-11-17 1900/week @ 2024-11-24 2149/week @ 2024-12-01 2391/week @ 2024-12-08 1720/week @ 2024-12-15 848/week @ 2024-12-22 491/week @ 2024-12-29 1343/week @ 2025-01-05 2148/week @ 2025-01-12

4,902 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

~245–700KB
~17K SLoC