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

#2420 in Procedural macros

Download history 1893/week @ 2024-11-17 2197/week @ 2024-11-24 2358/week @ 2024-12-01 2640/week @ 2024-12-08 2005/week @ 2024-12-15 1023/week @ 2024-12-22 778/week @ 2024-12-29 1625/week @ 2025-01-05 2574/week @ 2025-01-12 2767/week @ 2025-01-19 3138/week @ 2025-01-26 3660/week @ 2025-02-02 4075/week @ 2025-02-09 3543/week @ 2025-02-16 4195/week @ 2025-02-23 3948/week @ 2025-03-02

15,897 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

~195–630KB
~15K SLoC