parent
43fa1c68f3
commit
4d9ba931ee
4 changed files with 61 additions and 2 deletions
|
@ -47,6 +47,12 @@ impl Clone for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Error> for Box<dyn std::error::Error + Send> {
|
||||||
|
fn from(value: Error) -> Self {
|
||||||
|
Box::new(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents a success or a failure.
|
/// Represents a success or a failure.
|
||||||
///
|
///
|
||||||
/// Any failure is related to `std::io`, a Path Traversal
|
/// Any failure is related to `std::io`, a Path Traversal
|
||||||
|
|
|
@ -55,6 +55,12 @@ impl Clone for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Error> for Box<dyn std::error::Error + Send> {
|
||||||
|
fn from(value: Error) -> Self {
|
||||||
|
Box::new(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents a success or a failure within [kxio::net][crate::net].
|
/// Represents a success or a failure within [kxio::net][crate::net].
|
||||||
///
|
///
|
||||||
/// Any failure is related to `std::io`, a Path Traversal
|
/// Any failure is related to `std::io`, a Path Traversal
|
||||||
|
|
|
@ -89,7 +89,18 @@ impl Display for Plan {
|
||||||
for m in &self.match_request {
|
for m in &self.match_request {
|
||||||
write!(f, "{m} ")?;
|
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::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1104,7 +1115,7 @@ mod tests {
|
||||||
"=>",
|
"=>",
|
||||||
"Response {",
|
"Response {",
|
||||||
"url: \"http://no.url.provided.local/\",",
|
"url: \"http://no.url.provided.local/\",",
|
||||||
"status: 204,",
|
"status: 204 No Content,",
|
||||||
"headers: {\"foo\": \"bar\", \"baz\": \"buck\"}",
|
"headers: {\"foo\": \"bar\", \"baz\": \"buck\"}",
|
||||||
"}\n",
|
"}\n",
|
||||||
]
|
]
|
||||||
|
|
|
@ -10,5 +10,41 @@ pub enum Error {
|
||||||
}
|
}
|
||||||
impl std::error::Error for Error {}
|
impl std::error::Error for Error {}
|
||||||
|
|
||||||
|
impl From<Error> for Box<dyn std::error::Error + Send> {
|
||||||
|
fn from(value: Error) -> Self {
|
||||||
|
Box::new(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents a success or a failure using `fs` or `net`.
|
/// Represents a success or a failure using `fs` or `net`.
|
||||||
pub type Result<T> = core::result::Result<T, Error>;
|
pub type Result<T> = core::result::Result<T, Error>;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
|
||||||
|
// all errors should be Send
|
||||||
|
fn is_send<T: Send>() {}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn error_is_send() {
|
||||||
|
is_send::<crate::Error>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn base_error_can_be_boxed_send() {
|
||||||
|
let e = crate::Error::Fs(crate::fs::Error::IoString("test".to_string()));
|
||||||
|
let _box: Box<dyn std::error::Error + Send> = e.into();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fs_error_can_be_boxed_send() {
|
||||||
|
let e = crate::fs::Error::IoString("test".to_string());
|
||||||
|
let _box: Box<dyn std::error::Error + Send> = e.into();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn net_error_can_be_boxed_send() {
|
||||||
|
let e = crate::net::Error::NetIsNotAMock;
|
||||||
|
let _box: Box<dyn std::error::Error + Send> = e.into();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue