#byte-string

macro byte-strings-proc_macros

Internal: proc-macro backend of ::byte_strings

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

#1899 in Procedural macros

Download history 1501/week @ 2024-07-24 1058/week @ 2024-07-31 1357/week @ 2024-08-07 1647/week @ 2024-08-14 1419/week @ 2024-08-21 1198/week @ 2024-08-28 2215/week @ 2024-09-04 1762/week @ 2024-09-11 2072/week @ 2024-09-18 2205/week @ 2024-09-25 1921/week @ 2024-10-02 1761/week @ 2024-10-09 1838/week @ 2024-10-16 1893/week @ 2024-10-23 1697/week @ 2024-10-30 1522/week @ 2024-11-06

7,364 downloads per month
Used in 26 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

~220–660KB
~16K SLoC