Skip to content

Commit

Permalink
replace with macros, replace miette
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Apr 1, 2024
1 parent 524cbc1 commit 0043a4e
Show file tree
Hide file tree
Showing 63 changed files with 627 additions and 1,012 deletions.
76 changes: 59 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/kitsune-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ version.workspace = true
license.workspace = true

[dependencies]
eyre = "0.6.12"
isolang = { version = "2.4.0", features = ["serde"] }
miette = "7.2.0"
serde = { version = "1.0.197", features = ["derive"] }
smol_str = { version = "0.2.1", features = ["serde"] }
tokio = { version = "1.37.0", features = ["fs"] }
Expand Down
9 changes: 3 additions & 6 deletions crates/kitsune-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod server;
pub mod storage;
pub mod url;

use miette::{Context, IntoDiagnostic};
use eyre::{Result, WrapErr};
use serde::{Deserialize, Serialize};
use std::path::Path;
use tokio::fs;
Expand All @@ -41,17 +41,14 @@ pub struct Configuration {
}

impl Configuration {
pub async fn load<P>(path: P) -> miette::Result<Self>
pub async fn load<P>(path: P) -> Result<Self>
where
P: AsRef<Path>,
{
let content = fs::read_to_string(path)
.await
.into_diagnostic()
.wrap_err("Couldn't read configuration file")?;

toml::from_str(&content)
.into_diagnostic()
.wrap_err("Failed to parse configuration file")
toml::from_str(&content).wrap_err("Failed to parse configuration file")
}
}
1 change: 1 addition & 0 deletions crates/kitsune-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ build = "build.rs"
[dependencies]
async-trait = "0.1.79"
const_format = "0.2.32"
eyre = "0.6.12"
http = "1.1.0"
kitsune-db = { path = "../kitsune-db" }
kitsune-messaging = { path = "../kitsune-messaging" }
Expand Down
3 changes: 0 additions & 3 deletions crates/kitsune-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use http::StatusCode;
use std::borrow::Cow;
use std::error::Error as StdError;
use thiserror::Error;

pub type BoxError = Box<dyn StdError + Send + Sync>;

macro_rules! http_error {
($($variant_name:ident => $status_code:path),*$(,)?) => {
#[derive(Debug, Error)]
Expand Down
8 changes: 4 additions & 4 deletions crates/kitsune-core/src/traits/deliverer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::BoxError;
use async_trait::async_trait;
use eyre::Result;
use kitsune_db::model::{account::Account, favourite::Favourite, follower::Follow, post::Post};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
Expand All @@ -22,12 +22,12 @@ pub enum Action {

#[async_trait]
pub trait Deliverer: Send + Sync + 'static {
async fn deliver(&self, action: Action) -> Result<(), BoxError>;
async fn deliver(&self, action: Action) -> Result<()>;
}

#[async_trait]
impl Deliverer for Arc<dyn Deliverer> {
async fn deliver(&self, action: Action) -> Result<(), BoxError> {
async fn deliver(&self, action: Action) -> Result<()> {
(**self).deliver(action).await
}
}
Expand All @@ -37,7 +37,7 @@ impl<T> Deliverer for Vec<T>
where
T: Deliverer,
{
async fn deliver(&self, action: Action) -> Result<(), BoxError> {
async fn deliver(&self, action: Action) -> Result<()> {
for deliverer in self {
deliverer.deliver(action.clone()).await?;
}
Expand Down
Loading

0 comments on commit 0043a4e

Please sign in to comment.