From b06967e9b05ebe8491f8e06619b3e6a398958f9b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 9 Apr 2023 12:51:09 +0200 Subject: Add documentation on extension traits Signed-off-by: Matthias Beyer --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 6b120de..de501d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,15 @@ //! This crate adds the missing Option::inspect function via an extension trait //! +/// Extension trait for adding Option::inspect pub trait OptionInspect where F: FnOnce(&T), T: Sized, { + /// Inspect the Option + /// + /// Either call `f` on the value in `Some` or do nothing if this Option is a None. fn inspect(self, f: F) -> Self; } @@ -43,10 +47,12 @@ where } } +/// Extension trait for adding Option::inspect_none pub trait OptionInspectNone where F: FnOnce(), { + /// Call `f` if the Option this is called on is a None fn inspect_none(self, f: F) -> Self; } -- cgit v1.2.3