byte-strings

Crates.iobyte-strings
lib.rsbyte-strings
version0.3.1
sourcesrc
created_at2019-02-16 22:37:41.480084
updated_at2023-06-12 23:29:28.750968
descriptionRust byte strings manipulation, for a better and safer C FFI
homepage
repositoryhttps://github.com/danielhenrymantilla/byte-strings-rs
max_upload_size
id115259
size34,267
Daniel Henry-Mantilla (danielhenrymantilla)

documentation

https://docs.rs/byte-strings

README

::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!"));
}
Commit count: 19

cargo fmt