diff --git a/src/errors.rs b/src/errors.rs new file mode 100644 index 0000000..1e2baff --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,44 @@ +use std::{fmt::Display, string::FromUtf8Error}; + +#[derive(Debug)] +pub struct Error { + details: String, +} +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.details.to_string().as_str()) + } +} +impl From for Error { + fn from(value: FromUtf8Error) -> Self { + Self { + details: value.to_string(), + } + } +} +impl From for Error { + fn from(details: String) -> Self { + Self { details } + } +} +impl From for Error { + fn from(value: std::io::Error) -> Self { + Self { + details: value.to_string(), + } + } +} +impl From for Error { + fn from(value: atom_syndication::Error) -> Self { + Self { + details: value.to_string(), + } + } +} +impl From for Error { + fn from(value: reqwest::Error) -> Self { + Self { + details: value.to_string(), + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 60f9ca5..ad4e909 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,54 +1,11 @@ // https://www.phind.com/agent?cache=clke9xk39001cmj085upzho1t -use std::{fmt::Display, fs::File, string::FromUtf8Error}; +use std::fs::File; use atom_syndication::{Entry, Feed, Link}; -// -// ERRORS -// -#[derive(Debug)] -pub struct Error { - details: String, -} -impl Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(self.details.to_string().as_str()) - } -} -impl From for Error { - fn from(value: FromUtf8Error) -> Self { - Self { - details: value.to_string(), - } - } -} -impl From for Error { - fn from(details: String) -> Self { - Self { details } - } -} -impl From for Error { - fn from(value: std::io::Error) -> Self { - Self { - details: value.to_string(), - } - } -} -impl From for Error { - fn from(value: atom_syndication::Error) -> Self { - Self { - details: value.to_string(), - } - } -} -impl From for Error { - fn from(value: reqwest::Error) -> Self { - Self { - details: value.to_string(), - } - } -} +mod errors; +use errors::Error; // // RESULTS