fuck it whatever lmao

This commit is contained in:
KitsuneCafe 2024-02-17 08:27:25 -05:00
parent 8a89f841ab
commit 6b5b3520b0
6 changed files with 83 additions and 77 deletions

65
Cargo.lock generated
View file

@ -2,6 +2,71 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "anyhow"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca"
[[package]]
name = "proc-macro2"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]]
name = "roxy_core"
version = "0.1.0"
dependencies = [
"anyhow",
"thiserror",
]
[[package]]
name = "syn"
version = "2.0.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915aea9e586f80826ee59f8453c1101f9d1c4b3964cd2460185ee8e299ada496"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thiserror"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"

View file

@ -3,6 +3,6 @@ name = "roxy_core"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.79"
thiserror = "1.0.57"

View file

@ -1,94 +1,33 @@
use std::{
fmt::Display,
io::{Error as IOError, ErrorKind},
path::StripPrefixError,
string::FromUtf8Error,
};
use std::fmt::Display;
#[derive(Debug)]
#[derive(thiserror::Error, Debug)]
pub struct Error {
message: String,
source: Option<Box<dyn std::error::Error>>,
}
impl Error {
pub fn new<E: std::error::Error + 'static>(message: String, source: E) -> Self {
Self {
message,
source: Some(Box::new(source)),
}
}
fn wrap<E: std::error::Error + 'static>(value: E) -> Option<Box<dyn std::error::Error>> {
Some(Box::new(value))
}
#[source]
source: anyhow::Error,
}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", &self.message)?;
if let Some(source) = &self.source {
write!(f, " ({})", &source)?;
}
Ok(())
write!(f, "error: {} ", self.message).and_then(|_| self.source.fmt(f))
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.source.as_deref()
}
}
impl From<String> for Error {
fn from(value: String) -> Self {
Self {
message: value,
source: None,
}
}
}
impl From<StripPrefixError> for Error {
fn from(value: StripPrefixError) -> Self {
impl From<anyhow::Error> for Error {
fn from(value: anyhow::Error) -> Self {
Self {
message: value.to_string(),
source: Self::wrap(value),
source: value,
}
}
}
impl From<IOError> for Error {
fn from(value: IOError) -> Self {
Self {
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self{
message: value.to_string(),
source: Self::wrap(value),
source: anyhow::Error::from(value)
}
}
}
impl From<Error> for IOError {
fn from(value: Error) -> Self {
IOError::new(ErrorKind::Other, value.message)
}
}
impl From<FromUtf8Error> for Error {
fn from(value: FromUtf8Error) -> Self {
Self {
message: value.to_string(),
source: Self::wrap(value),
}
}
}
impl From<&'static dyn std::error::Error> for Error {
fn from(value: &'static dyn std::error::Error) -> Self {
Self {
message: value.to_string(),
source: Self::wrap(value),
}
}
}

View file

@ -1,3 +1,4 @@
pub mod roxy;
pub mod error;
pub mod result;

1
src/result.rs Normal file
View file

@ -0,0 +1 @@
pub type Result<T> = std::result::Result<T, crate::error::Error>;

View file

@ -108,7 +108,7 @@ impl Roxy {
fn read_asset(
asset: &mut Asset<BufReader<File>>,
parser: &mut Parser,
) -> Result<Vec<u8>, Error> {
) -> crate::result::Result<Vec<u8>> {
let mut src = Vec::new();
let mut dst = Vec::new();
@ -141,7 +141,7 @@ impl Roxy {
match path.with_extension("").file_name() {
Some(name) if name == "index" => Ok(path.to_path_buf()),
Some(_) => Ok(path.with_extension("").join("index.html")),
None => Err(Error::from("invalid path \"{path:?}\"".to_string())),
None => Err(anyhow::Error::msg("invalid path \"{path:?}\"").into()),
}
}