#thin #strings #null #null-terminated #efficiency

nightly null-terminated

Library of null-terminated slices and UTF-8-encoded strings with thin references

22 releases

Uses old Rust 2015

0.3.15 May 26, 2021
0.3.14 Dec 9, 2019
0.3.9 Apr 24, 2019
0.3.6 Dec 3, 2018
0.2.6 Dec 22, 2017

#570 in Rust patterns

Download history 30/week @ 2021-08-09 36/week @ 2021-08-16 36/week @ 2021-08-23 1/week @ 2021-08-30 11/week @ 2021-09-06 15/week @ 2021-09-13 11/week @ 2021-09-20 30/week @ 2021-09-27 10/week @ 2021-10-04 37/week @ 2021-10-11 10/week @ 2021-10-18 9/week @ 2021-10-25 33/week @ 2021-11-01 37/week @ 2021-11-08 7/week @ 2021-11-15 3/week @ 2021-11-22

179 downloads per month
Used in 9 crates (6 directly)

MIT/Apache

19KB
315 lines

null-terminated

Library of null-terminated slices and UTF-8-encoded strings, references to which are thin pointers for efficiency and ease of use with FFI

The likely primary use cases are C FFI and OS ABI (for example: on Unix, many system calls take, and the initial environment involves, null-terminated arguments).

As the representation is a bare pointer to the element type, one can declare foreign functions which merely take arguments or return values of type Nul<_>, for example:

extern "C" {
    fn strlen(_: &Nul<u8>) -> usize;
    fn strchr(_: &Nul<u8>, _: c_int) -> &Nul<u8>;
}

For further examples, see the docs of Nul.

License: MIT OR Apache-2.0


lib.rs:

Library of null-terminated slices and UTF-8-encoded strings, references to which are thin pointers for efficiency and ease of use with FFI

The likely primary use cases are C FFI and OS ABI (for example: on Unix, many system calls take, and the initial environment involves, null-terminated arguments).

As the representation is a bare pointer to the element type, one can declare foreign functions which merely take arguments or return values of type Nul<_>, for example:

# extern crate null_terminated; use null_terminated::Nul; type c_int = i32;
extern "C" {
    fn strlen(_: &Nul<u8>) -> usize;
    fn strchr(_: &Nul<u8>, _: c_int) -> &Nul<u8>;
}

For further examples, see the docs of Nul.

Dependencies

~16KB

Ǯ`