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

#1415 in Procedural macros

Download history 1704/week @ 2024-03-14 1598/week @ 2024-03-21 1874/week @ 2024-03-28 1435/week @ 2024-04-04 1443/week @ 2024-04-11 1591/week @ 2024-04-18 1839/week @ 2024-04-25 1632/week @ 2024-05-02 1075/week @ 2024-05-09 1320/week @ 2024-05-16 1207/week @ 2024-05-23 1365/week @ 2024-05-30 1415/week @ 2024-06-06 1278/week @ 2024-06-13 1203/week @ 2024-06-20 1083/week @ 2024-06-27

5,223 downloads per month
Used in 25 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!"));
}

lib.rs:

Crate not intended for direct use. Use https:://docs.rs/byte-strings instead.

Dependencies

~295–750KB
~18K SLoC