Skip to content

Commit

Permalink
rename enums for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Nov 9, 2023
1 parent d6a9efc commit 8fba940
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions crates/kitsune-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,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 Down
2 changes: 1 addition & 1 deletion crates/kitsune-captcha/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,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: 1 addition & 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
6 changes: 3 additions & 3 deletions crates/kitsune-core/src/activitypub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use kitsune_db::{
};
use kitsune_embed::Client as EmbedClient;
use kitsune_language::{DetectionBackend, Language};
use kitsune_search::{Search, SearchBackend};
use kitsune_search::{AnySearchBackend, SearchBackend};
use kitsune_type::ap::{object::MediaAttachment, Object, Tag, TagType};
use pulldown_cmark::{html, Options, Parser};
use scoped_futures::ScopedFutureExt;
Expand Down Expand Up @@ -117,7 +117,7 @@ pub struct ProcessNewObject<'a> {
embed_client: Option<&'a EmbedClient>,
object: Box<Object>,
fetcher: &'a Fetcher,
search_backend: &'a Search,
search_backend: &'a AnySearchBackend,
}

#[derive(TypedBuilder)]
Expand All @@ -129,7 +129,7 @@ struct PreprocessedObject<'a> {
content_lang: Language,
db_pool: &'a PgPool,
object: Box<Object>,
search_backend: &'a Search,
search_backend: &'a AnySearchBackend,
}

#[allow(clippy::missing_panics_doc)]
Expand Down
12 changes: 6 additions & 6 deletions crates/kitsune-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use self::{
use athena::JobQueue;
use eyre::Context;
use kitsune_cache::{ArcCache, InMemoryCache, NoopCache, RedisCache};
use kitsune_captcha::{hcaptcha::Captcha as HCaptcha, mcaptcha::Captcha as MCaptcha, Captcha};
use kitsune_captcha::{hcaptcha::Captcha as HCaptcha, mcaptcha::Captcha as MCaptcha, AnyCaptcha};
use kitsune_config::{
CacheConfiguration, CaptchaConfiguration, Configuration, EmailConfiguration,
MessagingConfiguration, SearchConfiguration, StorageConfiguration,
Expand All @@ -55,8 +55,8 @@ use kitsune_embed::Client as EmbedClient;
use kitsune_messaging::{
redis::RedisMessagingBackend, tokio_broadcast::TokioBroadcastMessagingBackend, MessagingHub,
};
use kitsune_search::{NoopSearchService, Search, SqlSearchService};
use kitsune_storage::{fs::Storage as FsStorage, s3::Storage as S3Storage, Storage};
use kitsune_search::{AnySearchBackend, NoopSearchService, SqlSearchService};
use kitsune_storage::{fs::Storage as FsStorage, s3::Storage as S3Storage, AnyStorageBackend};
use rusty_s3::{Bucket as S3Bucket, Credentials as S3Credentials};
use serde::{de::DeserializeOwned, Serialize};
use service::search::SearchService;
Expand Down Expand Up @@ -100,7 +100,7 @@ where
Arc::new(cache)
}

fn prepare_captcha(config: &CaptchaConfiguration) -> Captcha {
fn prepare_captcha(config: &CaptchaConfiguration) -> AnyCaptcha {
match config {
CaptchaConfiguration::HCaptcha(config) => HCaptcha::builder()
.verify_url(config.verify_url.to_string())
Expand All @@ -118,7 +118,7 @@ fn prepare_captcha(config: &CaptchaConfiguration) -> Captcha {
}
}

fn prepare_storage(config: &Configuration) -> eyre::Result<Storage> {
fn prepare_storage(config: &Configuration) -> eyre::Result<AnyStorageBackend> {
let storage = match config.storage {
StorageConfiguration::Fs(ref fs_config) => {
FsStorage::new(fs_config.upload_dir.as_str().into()).into()
Expand Down Expand Up @@ -188,7 +188,7 @@ async fn prepare_messaging(config: &Configuration) -> eyre::Result<MessagingHub>
async fn prepare_search(
search_config: &SearchConfiguration,
db_pool: &PgPool,
) -> eyre::Result<Search> {
) -> eyre::Result<AnySearchBackend> {
let service = match search_config {
SearchConfiguration::Meilisearch(_config) => {
#[cfg(not(feature = "meilisearch"))]
Expand Down
4 changes: 2 additions & 2 deletions crates/kitsune-core/src/service/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use kitsune_db::{
PgPool,
};
use kitsune_http_client::Client;
use kitsune_storage::{BoxError, Storage, StorageBackend};
use kitsune_storage::{AnyStorageBackend, BoxError, StorageBackend};
use scoped_futures::ScopedFutureExt;
use speedy_uuid::Uuid;
use typed_builder::TypedBuilder;
Expand Down Expand Up @@ -89,7 +89,7 @@ pub struct AttachmentService {
db_pool: PgPool,
media_proxy_enabled: bool,
#[builder(setter(into))]
storage_backend: Storage,
storage_backend: AnyStorageBackend,
url_service: UrlService,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/kitsune-core/src/service/captcha.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::error::Result;
use kitsune_captcha::{Captcha, CaptchaBackend, ChallengeStatus};
use kitsune_captcha::{AnyCaptcha, CaptchaBackend, ChallengeStatus};
use typed_builder::TypedBuilder;

#[derive(Clone, TypedBuilder)]
pub struct CaptchaService {
#[builder(setter(into))]
pub backend: Option<Captcha>,
pub backend: Option<AnyCaptcha>,
}

impl CaptchaService {
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-core/src/service/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ pub struct PostService {
instance_service: InstanceService,
job_service: JobService,
post_resolver: PostResolver,
search_backend: kitsune_search::Search,
search_backend: kitsune_search::AnySearchBackend,
status_event_emitter: PostEventEmitter,
url_service: UrlService,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/kitsune-core/src/service/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ pub struct Search<'a> {
pub struct SearchService {
db_pool: PgPool,
fetcher: Fetcher,
search_backend: kitsune_search::Search,
search_backend: kitsune_search::AnySearchBackend,
}

impl SearchService {
#[must_use]
pub fn backend(&self) -> &kitsune_search::Search {
pub fn backend(&self) -> &kitsune_search::AnySearchBackend {
&self.search_backend
}

Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-oidc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct UserInfo {
#[derive(Clone)]
pub struct OidcService {
client: CoreClient,
login_state_store: self::state::StoreBackend,
login_state_store: self::state::AnyStore,
}

impl OidcService {
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-oidc/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use openidconnect::{Nonce, PkceCodeVerifier};
use serde::{Deserialize, Serialize};
use speedy_uuid::Uuid;

pub use self::store::{Store, StoreBackend};
pub use self::store::{AnyStore, Store};

pub mod store;

Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-oidc/src/state/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod redis;

#[derive(Clone)]
#[enum_dispatch(Store)]
pub enum StoreBackend {
pub enum AnyStore {
InMemory(in_memory::InMemory),
Redis(redis::Redis),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-search/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Result<T, E = Error> = std::result::Result<T, E>;

#[derive(Clone)]
#[enum_dispatch(SearchBackend)]
pub enum Search {
pub enum AnySearchBackend {
#[cfg(feature = "meilisearch")]
Meilisearch(MeiliSearchService),
Noop(NoopSearchService),
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub trait StorageBackend: Clone + Send + Sync {
#[derive(Clone)]
#[enum_dispatch(StorageBackend)]
/// Combined storage enum for enum dispatch
pub enum Storage {
pub enum AnyStorageBackend {
/// File system-backed storage
Fs(fs::Storage),

Expand Down
8 changes: 4 additions & 4 deletions kitsune/src/http/graphql/types/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ pub enum CaptchaBackend {
MCaptcha,
}

impl From<kitsune_captcha::Captcha> for CaptchaInfo {
fn from(e: kitsune_captcha::Captcha) -> Self {
impl From<kitsune_captcha::AnyCaptcha> for CaptchaInfo {
fn from(e: kitsune_captcha::AnyCaptcha) -> Self {
match e {
kitsune_captcha::Captcha::HCaptcha(config) => Self {
kitsune_captcha::AnyCaptcha::HCaptcha(config) => Self {
backend: CaptchaBackend::HCaptcha,
key: config.site_key,
},
kitsune_captcha::Captcha::MCaptcha(config) => Self {
kitsune_captcha::AnyCaptcha::MCaptcha(config) => Self {
backend: CaptchaBackend::MCaptcha,
key: config.widget_link,
},
Expand Down

0 comments on commit 8fba940

Please sign in to comment.