Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4815f29

Browse files
committedJun 24, 2024
document the cvt methods
1 parent 12ec5b7 commit 4815f29

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed
 

‎std/src/sys/pal/unix/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,13 @@ macro_rules! impl_is_minus_one {
307307

308308
impl_is_minus_one! { i8 i16 i32 i64 isize }
309309

310+
/// Convert native return values to Result using the *-1 means error is in `errno`* convention.
311+
/// Non-error values are `Ok`-wrapped.
310312
pub fn cvt<T: IsMinusOne>(t: T) -> crate::io::Result<T> {
311313
if t.is_minus_one() { Err(crate::io::Error::last_os_error()) } else { Ok(t) }
312314
}
313315

316+
/// `-1` → look at `errno` → retry on `EINTR`. Otherwise `Ok()`-wrap the closure return value.
314317
pub fn cvt_r<T, F>(mut f: F) -> crate::io::Result<T>
315318
where
316319
T: IsMinusOne,
@@ -325,6 +328,7 @@ where
325328
}
326329

327330
#[allow(dead_code)] // Not used on all platforms.
331+
/// Zero means `Ok()`, all other values are treated as raw OS errors. Does not look at `errno`.
328332
pub fn cvt_nz(error: libc::c_int) -> crate::io::Result<()> {
329333
if error == 0 { Ok(()) } else { Err(crate::io::Error::from_raw_os_error(error)) }
330334
}

0 commit comments

Comments
 (0)
Failed to load comments.