From cce6662d635bb2115f9f2a7bab92cc105166e761 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 18 Sep 2024 01:27:47 -0400 Subject: App methods now return errors that allow not-found cases to be distinguished. --- src/repo/error.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/repo/error.rs (limited to 'src/repo/error.rs') diff --git a/src/repo/error.rs b/src/repo/error.rs new file mode 100644 index 0000000..a5961e2 --- /dev/null +++ b/src/repo/error.rs @@ -0,0 +1,23 @@ +pub trait NotFound { + type Ok; + fn not_found(self, map: F) -> Result + where + E: From, + F: FnOnce() -> E; +} + +impl NotFound for Result { + type Ok = T; + + fn not_found(self, map: F) -> Result + where + E: From, + F: FnOnce() -> E, + { + match self { + Err(sqlx::Error::RowNotFound) => Err(map()), + Err(other) => Err(other.into()), + Ok(value) => Ok(value), + } + } +} -- cgit v1.2.3