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

#1326 in Procedural macros

Download history 3029/week @ 2023-12-08 1791/week @ 2023-12-15 891/week @ 2023-12-22 944/week @ 2023-12-29 2073/week @ 2024-01-05 1796/week @ 2024-01-12 2217/week @ 2024-01-19 1698/week @ 2024-01-26 1444/week @ 2024-02-02 2049/week @ 2024-02-09 1858/week @ 2024-02-16 1971/week @ 2024-02-23 1976/week @ 2024-03-01 1510/week @ 2024-03-08 1725/week @ 2024-03-15 1348/week @ 2024-03-22

6,794 downloads per month
Used in 24 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

~320–770KB
~18K SLoC