#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

#400 in Rust patterns

Download history 1928/week @ 2024-01-05 1715/week @ 2024-01-12 2119/week @ 2024-01-19 1607/week @ 2024-01-26 1377/week @ 2024-02-02 1943/week @ 2024-02-09 1723/week @ 2024-02-16 1919/week @ 2024-02-23 1901/week @ 2024-03-01 1407/week @ 2024-03-08 1580/week @ 2024-03-15 1471/week @ 2024-03-22 1772/week @ 2024-03-29 1219/week @ 2024-04-05 1245/week @ 2024-04-12 1271/week @ 2024-04-19

5,722 downloads per month
Used in 13 crates (9 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

~320–770KB
~18K SLoC