unixstring codecov Crates.io Docs

UnixString is an FFI-friendly null-terminated byte string that may be constructed from a [String], a CString, a PathBuf, an OsString or a collection of bytes.

An UnixString can then be converted into a slice of CStr, Path or OsStr in infallible and zero-cost operations.

Example

```rust use std::{convert::TryFrom, env};

use unixstring::UnixString;

fn stat(path: &UnixString) -> std::io::Result { // Safety: The all-zero byte-pattern is a valid struct stat let mut stat_buf = unsafe { std::mem::zeroed() };

if -1 == unsafe { libc::lstat(path.as_ptr(), &mut stat_buf) } {
    let io_err = std::io::Error::last_os_error();
    Err(io_err)
} else {
    Ok(stat_buf)
}

}

fn main() -> std::io::Result<()>{ for arg in env::argsos().map(UnixString::tryfrom).flatten() { let stat = stat(&arg)?;

    let size = stat.st_size;

    println!("{} occupies {} bytes.", arg.as_path().display(), size);
}

Ok(())

} ```