#byte-string #macro #better #safer #proc-macro #backing

macro byte-strings-proc-macro

https://crates.io/crates/byte-strings backing proc-macros

2 releases

0.1.1 Feb 18, 2019
0.1.0 Feb 16, 2019

#9 in #safer

Download history 52/week @ 2024-07-22 23/week @ 2024-07-29 14/week @ 2024-08-05 41/week @ 2024-08-12 24/week @ 2024-08-19 44/week @ 2024-08-26 36/week @ 2024-09-02 25/week @ 2024-09-09 23/week @ 2024-09-16 41/week @ 2024-09-23 24/week @ 2024-09-30 18/week @ 2024-10-07 63/week @ 2024-10-14 30/week @ 2024-10-21 23/week @ 2024-10-28 37/week @ 2024-11-04

154 downloads per month

MIT license

25KB
678 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

~2MB
~48K SLoC