aboutsummaryrefslogtreecommitdiff
path: root/src/raw/mod.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2020-05-02 14:12:54 +0200
committerDaniel Schadt <kingdread@gmx.de>2020-05-02 14:12:54 +0200
commit69f8feb33465de6213963c1aadf955704bb83a08 (patch)
tree7a737d2718fbeb030365f49aeba02846881935f9 /src/raw/mod.rs
parentd3e0d1bd58115f581cae6441c863ba85805007ff (diff)
downloadevtclib-69f8feb33465de6213963c1aadf955704bb83a08.tar.gz
evtclib-69f8feb33465de6213963c1aadf955704bb83a08.tar.bz2
evtclib-69f8feb33465de6213963c1aadf955704bb83a08.zip
add more documentation
Diffstat (limited to 'src/raw/mod.rs')
-rw-r--r--src/raw/mod.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/raw/mod.rs b/src/raw/mod.rs
index 77a8571..0b17933 100644
--- a/src/raw/mod.rs
+++ b/src/raw/mod.rs
@@ -33,6 +33,15 @@ pub fn parse_zip<R: Read + Seek>(input: R) -> ParseResult<Evtc> {
/// at the first nul byte instead of raising an error.
///
/// If the slice does not end with a nul byte, this function returns `None`.
+///
+/// ```
+/// # use evtclib::raw::cstr_up_to_nul;
+/// # fn doctest() -> Option<()> {
+/// assert_eq!(cstr_up_to_nul(b"foo\0bar\0")?.to_bytes(), b"foo");
+/// # Some(())
+/// # }
+/// # doctest().unwrap();
+/// ```
pub fn cstr_up_to_nul(bytes: &[u8]) -> Option<&CStr> {
let index = bytes.iter().position(|c| *c == 0)?;
CStr::from_bytes_with_nul(&bytes[..index + 1]).ok()