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

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

#15 in #safer

Download history 4/week @ 2023-12-04 132/week @ 2023-12-11 17/week @ 2024-01-08 15/week @ 2024-01-15 1/week @ 2024-01-29 1/week @ 2024-02-05 7/week @ 2024-02-12 25/week @ 2024-02-19 58/week @ 2024-02-26 7/week @ 2024-03-04 17/week @ 2024-03-11 22/week @ 2024-03-18

106 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
~45K SLoC