From 9677461de3e6a56f6ad871a986e2829b6f836136 Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Sat, 20 Jul 2024 23:24:46 +0100 Subject: [PATCH] Include `and_then` for `HeaderValue` --- fitsio/src/headers.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fitsio/src/headers.rs b/fitsio/src/headers.rs index 0a610f55..511be539 100644 --- a/fitsio/src/headers.rs +++ b/fitsio/src/headers.rs @@ -59,7 +59,7 @@ where self.comment.as_ref() } - /// Map the _value_ of a `HeaderValue` to another form + /// Map the _value_ of a [`HeaderValue`] to another form pub fn map(self, f: F) -> HeaderValue where F: FnOnce(T) -> U, @@ -69,6 +69,20 @@ where comment: self.comment, } } + + /// Monadic "bind" for [`HeaderValue`] + pub fn and_then(self, f: F) -> Result> + where + F: FnOnce(T) -> Result, + { + match f(self.value) { + Ok(value) => Ok(HeaderValue { + value, + comment: self.comment, + }), + Err(e) => Err(e), + } + } } /**