Skip to content

Commit

Permalink
Use nightly features (#413)
Browse files Browse the repository at this point in the history
* remove async_trait

* finish port

* get rid of warnings

* adjust versions to nightly

* remove devshell prompt

* flake.lock: Update

Flake lock file updates:

• Updated input 'rust-overlay':
    'github:oxalica/rust-overlay/8a9d6f544c08ee898c7f3761cc9587be7565db5e' (2023-11-07)
  → 'github:oxalica/rust-overlay/58240e1ac627cef3ea30c7732fedfb4f51afd8e7' (2023-11-08)

* make use of nightly features

* rename enums for consistency

* use a lot more impl in traits

* add own cowbox type

* flake.lock: Update

Flake lock file updates:

• Updated input 'rust-overlay':
    'github:oxalica/rust-overlay/58240e1ac627cef3ea30c7732fedfb4f51afd8e7' (2023-11-08)
  → 'github:oxalica/rust-overlay/603e4962d7d2225ba2caf66b0eabfcaa9a93c490' (2023-11-09)

* box preprocess future

* rename enum case

* remove boxed calls

* reduce size of state
  • Loading branch information
aumetra authored Nov 10, 2023
1 parent 6aaa2c2 commit 22efa4a
Show file tree
Hide file tree
Showing 74 changed files with 484 additions and 406 deletions.
4 changes: 0 additions & 4 deletions .devshell_prompt.sh

This file was deleted.

36 changes: 12 additions & 24 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ members = [
"crates/kitsune-storage",
"crates/kitsune-test",
"crates/kitsune-type",
"crates/kitsune-util",
"kitsune",
"kitsune-cli",
"kitsune-job-runner",
Expand Down
1 change: 0 additions & 1 deletion crates/kitsune-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ edition.workspace = true
version.workspace = true

[dependencies]
async-trait = "0.1.74"
deadpool-redis = "0.13.0"
enum_dispatch = "0.3.12"
moka = { version = "0.12.1", features = ["sync"] }
Expand Down
2 changes: 0 additions & 2 deletions crates/kitsune-cache/src/in_memory.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{CacheBackend, CacheResult};
use async_trait::async_trait;
use moka::sync::Cache;
use std::{fmt::Display, marker::PhantomData, time::Duration};

Expand Down Expand Up @@ -30,7 +29,6 @@ where
}
}

#[async_trait]
impl<K, V> CacheBackend<K, V> for InMemory<K, V>
where
K: Display + Send + Sync + ?Sized,
Expand Down
8 changes: 3 additions & 5 deletions crates/kitsune-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#[macro_use]
extern crate tracing;

use async_trait::async_trait;
use enum_dispatch::enum_dispatch;
use serde::{de::DeserializeOwned, Serialize};
use std::{fmt::Display, sync::Arc};
Expand All @@ -19,10 +18,10 @@ mod redis;

type CacheResult<T, E = Error> = Result<T, E>;

pub type ArcCache<K, V> = Arc<Cache<K, V>>;
pub type ArcCache<K, V> = Arc<AnyCache<K, V>>;

#[enum_dispatch(CacheBackend<K, V>)]
pub enum Cache<K, V>
pub enum AnyCache<K, V>
where
K: Display + Send + Sync + ?Sized,
V: Clone + DeserializeOwned + Serialize + Send + Sync + 'static,
Expand All @@ -32,8 +31,8 @@ where
Redis(RedisCache<K, V>),
}

#[async_trait]
#[enum_dispatch]
#[allow(async_fn_in_trait)] // Because of `enum_dispatch`
pub trait CacheBackend<K, V>: Send + Sync
where
K: ?Sized,
Expand All @@ -46,7 +45,6 @@ where
#[derive(Clone)]
pub struct NoopCache;

#[async_trait]
impl<K, V> CacheBackend<K, V> for NoopCache
where
K: Send + Sync + ?Sized,
Expand Down
2 changes: 0 additions & 2 deletions crates/kitsune-cache/src/redis.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::{CacheBackend, CacheResult};
use async_trait::async_trait;
use redis::AsyncCommands;
use serde::{de::DeserializeOwned, Serialize};
use std::{fmt::Display, marker::PhantomData, time::Duration};
Expand Down Expand Up @@ -44,7 +43,6 @@ where
}
}

#[async_trait]
impl<K, V> CacheBackend<K, V> for Redis<K, V>
where
K: Display + Send + Sync + ?Sized,
Expand Down
1 change: 0 additions & 1 deletion crates/kitsune-captcha/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version.workspace = true
edition.workspace = true

[dependencies]
async-trait = "0.1.74"
enum_dispatch = "0.3.12"
http = "0.2.9"
kitsune-http-client = { path = "../kitsune-http-client" }
Expand Down
2 changes: 0 additions & 2 deletions crates/kitsune-captcha/src/hcaptcha.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{error::CaptchaVerification, CaptchaBackend, ChallengeStatus, Result};
use async_trait::async_trait;
use http::Request;
use kitsune_http_client::Client;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -34,7 +33,6 @@ struct HCaptchaResponse {
error_codes: Option<Vec<CaptchaVerification>>, // optional: any error codes
}

#[async_trait]
impl CaptchaBackend for Captcha {
async fn verify(&self, token: &str) -> Result<ChallengeStatus> {
let body = Body::builder()
Expand Down
5 changes: 2 additions & 3 deletions crates/kitsune-captcha/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![allow(forbidden_lint_groups)]

use self::error::CaptchaVerification;
use async_trait::async_trait;
use enum_dispatch::enum_dispatch;

pub mod error;
Expand All @@ -27,8 +26,8 @@ pub enum ChallengeStatus {
}

/// Trait abstraction over captcha backends
#[async_trait]
#[enum_dispatch]
#[allow(async_fn_in_trait)] // Because of `enum_dispatch`
pub trait CaptchaBackend: Clone + Send + Sync {
/// Verify the token provided in the registration form
async fn verify(&self, token: &str) -> Result<ChallengeStatus>;
Expand All @@ -37,7 +36,7 @@ pub trait CaptchaBackend: Clone + Send + Sync {
#[derive(Clone)]
#[enum_dispatch(CaptchaBackend)]
/// Combined captcha enum for enum dispatch
pub enum Captcha {
pub enum AnyCaptcha {
/// hCaptcha
HCaptcha(hcaptcha::Captcha),

Expand Down
2 changes: 0 additions & 2 deletions crates/kitsune-captcha/src/mcaptcha.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{CaptchaBackend, ChallengeStatus, Result};
use async_trait::async_trait;
use http::Request;
use kitsune_http_client::Client;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -28,7 +27,6 @@ struct Body {
secret: String,
}

#[async_trait]
impl CaptchaBackend for Captcha {
async fn verify(&self, token: &str) -> Result<ChallengeStatus> {
let body = Body::builder()
Expand Down
6 changes: 3 additions & 3 deletions crates/kitsune-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ ammonia = "3.3.0"
argon2 = "0.5.2"
async-recursion = "1.0.5"
async-stream = "0.3.5"
async-trait = "0.1.74"
athena = { path = "../../lib/athena" }
autometrics = { version = "0.6.0", default-features = false, features = [
"metrics",
] }
base64-simd = "0.8.0"
base64-simd = { version = "0.8.0", features = ["unstable"] }
bytes = "1.5.0"
const_format = "0.2.32"
deadpool-redis = "0.13.0"
Expand All @@ -32,7 +31,7 @@ garde = { version = "0.16.2", default-features = false, features = [
] }
globset = "0.4.13"
headers = "0.3.9"
hex-simd = "0.8.0"
hex-simd = { version = "0.8.0", features = ["unstable"] }
http = "0.2.9"
img-parts = "0.3.0"
iso8601-timestamp = "0.2.12"
Expand All @@ -50,6 +49,7 @@ kitsune-messaging = { path = "../kitsune-messaging" }
kitsune-search = { path = "../kitsune-search" }
kitsune-storage = { path = "../kitsune-storage" }
kitsune-type = { path = "../kitsune-type" }
kitsune-util = { path = "../kitsune-util" }
mime = "0.3.17"
mime_guess = { version = "2.0.4", default-features = false }
password-hash = { version = "0.5.0", features = ["std"] }
Expand Down
3 changes: 2 additions & 1 deletion crates/kitsune-core/src/activitypub/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub struct Fetcher {
embed_client: Option<EmbedClient>,
federation_filter: FederationFilterService,
#[builder(setter(into))]
search_backend: kitsune_search::Search,
search_backend: kitsune_search::AnySearchBackend,
webfinger: Webfinger,

// Caches
Expand Down Expand Up @@ -180,6 +180,7 @@ impl Fetcher {
let fetch_webfinger = opts
.acct
.map_or(true, |acct| acct != (&actor.preferred_username, domain));

let used_webfinger = if fetch_webfinger {
match self
.webfinger
Expand Down
Loading

0 comments on commit 22efa4a

Please sign in to comment.