#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

#588 in Rust patterns

Download history 1464/week @ 2024-03-24 1636/week @ 2024-03-31 1233/week @ 2024-04-07 1384/week @ 2024-04-14 1508/week @ 2024-04-21 1827/week @ 2024-04-28 1139/week @ 2024-05-05 853/week @ 2024-05-12 1423/week @ 2024-05-19 1164/week @ 2024-05-26 1144/week @ 2024-06-02 1322/week @ 2024-06-09 905/week @ 2024-06-16 1306/week @ 2024-06-23 682/week @ 2024-06-30 1274/week @ 2024-07-07

4,242 downloads per month
Used in 14 crates (10 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

~300–760KB
~18K SLoC