mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-28 06:23:08 -08:00
chore(examples): add examples to docs
Signed-off-by: Paul Spooren <mail@aparcar.org>
This commit is contained in:
@@ -435,4 +435,12 @@ mod tests {
|
|||||||
assert!(matches!(file.write(&buf), Err(_)));
|
assert!(matches!(file.write(&buf), Err(_)));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_nullfd_read_write() {
|
||||||
|
let nullfd = open_nullfd().unwrap();
|
||||||
|
let mut buf = vec![0u8; 16];
|
||||||
|
assert_eq!(rustix::io::read(&nullfd, &mut buf).unwrap(), 0);
|
||||||
|
assert!(rustix::io::write(&nullfd, b"test").is_err());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,15 @@
|
|||||||
/// A helper trait for turning any type value into `Some(value)`.
|
/// A helper trait for turning any type value into `Some(value)`.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use rosenpass_util::option::SomeExt;
|
||||||
|
///
|
||||||
|
/// let x = 42;
|
||||||
|
/// let y = x.some();
|
||||||
|
///
|
||||||
|
/// assert_eq!(y, Some(42));
|
||||||
|
/// ```
|
||||||
pub trait SomeExt: Sized {
|
pub trait SomeExt: Sized {
|
||||||
/// Wraps the calling value in `Some()`.
|
/// Wraps the calling value in `Some()`.
|
||||||
fn some(self) -> Option<Self> {
|
fn some(self) -> Option<Self> {
|
||||||
|
|||||||
@@ -5,6 +5,16 @@ use std::time::Instant;
|
|||||||
/// This is a simple wrapper around `std::time::Instant` that provides a
|
/// This is a simple wrapper around `std::time::Instant` that provides a
|
||||||
/// convenient way to get the seconds elapsed since the creation of the
|
/// convenient way to get the seconds elapsed since the creation of the
|
||||||
/// `Timebase` instance.
|
/// `Timebase` instance.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use rosenpass_util::time::Timebase;
|
||||||
|
///
|
||||||
|
/// let timebase = Timebase::default();
|
||||||
|
/// let now = timebase.now();
|
||||||
|
/// assert!(now > 0.0);
|
||||||
|
/// ```
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Timebase(Instant);
|
pub struct Timebase(Instant);
|
||||||
|
|||||||
@@ -1,6 +1,20 @@
|
|||||||
use zeroize::Zeroize;
|
use zeroize::Zeroize;
|
||||||
|
|
||||||
/// Extension trait providing a method for zeroizing a value and returning it
|
/// Extension trait providing a method for zeroizing a value and returning it
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// use zeroize::Zeroize;
|
||||||
|
/// use rosenpass_util::zeroize::ZeroizedExt;
|
||||||
|
///
|
||||||
|
/// let mut value = String::from("hello");
|
||||||
|
/// value.zeroize();
|
||||||
|
/// assert_eq!(value, "");
|
||||||
|
///
|
||||||
|
/// let value = String::from("hello").zeroized();
|
||||||
|
/// assert_eq!(value, "");
|
||||||
|
/// ```
|
||||||
pub trait ZeroizedExt: Zeroize + Sized {
|
pub trait ZeroizedExt: Zeroize + Sized {
|
||||||
/// Zeroizes the value in place and returns self
|
/// Zeroizes the value in place and returns self
|
||||||
fn zeroized(mut self) -> Self {
|
fn zeroized(mut self) -> Self {
|
||||||
|
|||||||
Reference in New Issue
Block a user