diff --git a/src/fs/result.rs b/src/fs/result.rs index d7505d3..96d9a07 100644 --- a/src/fs/result.rs +++ b/src/fs/result.rs @@ -47,6 +47,12 @@ impl Clone for Error { } } +impl From for Box { + fn from(value: Error) -> Self { + Box::new(value) + } +} + /// Represents a success or a failure. /// /// Any failure is related to `std::io`, a Path Traversal diff --git a/src/net/result.rs b/src/net/result.rs index fa1bb66..09dbaa2 100644 --- a/src/net/result.rs +++ b/src/net/result.rs @@ -55,6 +55,12 @@ impl Clone for Error { } } +impl From for Box { + fn from(value: Error) -> Self { + Box::new(value) + } +} + /// Represents a success or a failure within [kxio::net][crate::net]. /// /// Any failure is related to `std::io`, a Path Traversal diff --git a/src/net/system.rs b/src/net/system.rs index 460678a..f79646f 100644 --- a/src/net/system.rs +++ b/src/net/system.rs @@ -89,7 +89,18 @@ impl Display for Plan { for m in &self.match_request { write!(f, "{m} ")?; } - writeln!(f, "=> {:?}", self.response) + writeln!( + f, + "=> Response {{ url: \"{}\", status: {}, headers: {{{}}} }}", + self.response.url(), + self.response.status(), + self.response + .headers() + .iter() + .map(|(k, v)| format!("{k:?}: {v:?}")) + .collect::>() + .join(", ") + ) } } @@ -1104,7 +1115,7 @@ mod tests { "=>", "Response {", "url: \"http://no.url.provided.local/\",", - "status: 204,", + "status: 204 No Content,", "headers: {\"foo\": \"bar\", \"baz\": \"buck\"}", "}\n", ] diff --git a/src/result.rs b/src/result.rs index 40230b0..0ff7531 100644 --- a/src/result.rs +++ b/src/result.rs @@ -10,5 +10,41 @@ pub enum Error { } impl std::error::Error for Error {} +impl From for Box { + fn from(value: Error) -> Self { + Box::new(value) + } +} + /// Represents a success or a failure using `fs` or `net`. pub type Result = core::result::Result; + +#[cfg(test)] +mod tests { + + // all errors should be Send + fn is_send() {} + + #[test] + fn error_is_send() { + is_send::(); + } + + #[test] + fn base_error_can_be_boxed_send() { + let e = crate::Error::Fs(crate::fs::Error::IoString("test".to_string())); + let _box: Box = e.into(); + } + + #[test] + fn fs_error_can_be_boxed_send() { + let e = crate::fs::Error::IoString("test".to_string()); + let _box: Box = e.into(); + } + + #[test] + fn net_error_can_be_boxed_send() { + let e = crate::net::Error::NetIsNotAMock; + let _box: Box = e.into(); + } +}