extract errors.rs

This commit is contained in:
Paul Campbell 2023-07-25 10:36:08 +01:00
parent 43be49910b
commit ec20864dac
2 changed files with 47 additions and 46 deletions

44
src/errors.rs Normal file
View file

@ -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<FromUtf8Error> for Error {
fn from(value: FromUtf8Error) -> Self {
Self {
details: value.to_string(),
}
}
}
impl From<String> for Error {
fn from(details: String) -> Self {
Self { details }
}
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self {
details: value.to_string(),
}
}
}
impl From<atom_syndication::Error> for Error {
fn from(value: atom_syndication::Error) -> Self {
Self {
details: value.to_string(),
}
}
}
impl From<reqwest::Error> for Error {
fn from(value: reqwest::Error) -> Self {
Self {
details: value.to_string(),
}
}
}

View file

@ -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<FromUtf8Error> for Error {
fn from(value: FromUtf8Error) -> Self {
Self {
details: value.to_string(),
}
}
}
impl From<String> for Error {
fn from(details: String) -> Self {
Self { details }
}
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self {
details: value.to_string(),
}
}
}
impl From<atom_syndication::Error> for Error {
fn from(value: atom_syndication::Error) -> Self {
Self {
details: value.to_string(),
}
}
}
impl From<reqwest::Error> for Error {
fn from(value: reqwest::Error) -> Self {
Self {
details: value.to_string(),
}
}
}
mod errors;
use errors::Error;
//
// RESULTS