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

macro byte-strings-proc-macro

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

2 个版本

0.1.1 2019年2月18日
0.1.0 2019年2月16日

#12 in #safer

Download history 17/week @ 2024-03-13 21/week @ 2024-03-20 31/week @ 2024-03-27 60/week @ 2024-04-03 35/week @ 2024-04-10 14/week @ 2024-04-17 17/week @ 2024-04-24 8/week @ 2024-05-01 20/week @ 2024-05-08 17/week @ 2024-05-15 9/week @ 2024-05-22 23/week @ 2024-05-29 25/week @ 2024-06-05 17/week @ 2024-06-12 19/week @ 2024-06-19 33/week @ 2024-06-26

96 每月下载量

MIT 许可证

25KB
678 代码行数(不含注释)

::byte-strings

Rust 零成本字节字符串操作,为更好的 FFI 提供安全保障

Repository Latest version Documentation MSRV License CI

示例

包含 c_str! 宏,用于创建 有效的 C 字符串字面量,且没有任何运行时成本!

#[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!"));
}

依赖项

~2MB
~46K SLoC