Make eligible enums convertable to static strs

This commit is contained in:
SleeplessOne1917 2024-07-22 13:04:23 -04:00
parent 572a42d880
commit 87a2af4b5d
14 changed files with 414 additions and 402 deletions

762
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -149,8 +149,7 @@ regex = "1.10.4"
once_cell = "1.19.0"
diesel-derive-newtype = "2.1.2"
diesel-derive-enum = { version = "2.1.0", features = ["postgres"] }
strum = "0.26.2"
strum_macros = "0.26.4"
strum = { version = "0.26.3", features = ["derive"] }
itertools = "0.13.0"
futures = "0.3.30"
http = "0.2.12"

View file

@ -31,7 +31,7 @@ serde = { workspace = true }
actix-web = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
strum_macros = { workspace = true }
strum = { workspace = true }
url = { workspace = true }
http = { workspace = true }
futures = { workspace = true }

View file

@ -13,10 +13,10 @@ use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{source::community::Community, traits::Crud};
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
use serde::{Deserialize, Serialize};
use strum_macros::Display;
use strum::{Display, IntoStaticStr};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, Display)]
#[derive(Clone, Debug, Display, Deserialize, Serialize, IntoStaticStr)]
pub enum LockType {
Lock,
}

View file

@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use strum_macros::Display;
use strum::{Display, IntoStaticStr};
pub mod block;
pub mod community;
@ -8,7 +8,7 @@ pub mod deletion;
pub mod following;
pub mod voting;
#[derive(Clone, Debug, Display, Deserialize, Serialize, PartialEq, Eq)]
#[derive(Clone, Debug, Display, IntoStaticStr, Deserialize, Serialize, PartialEq, Eq)]
pub enum CreateOrUpdateType {
Create,
Update,

View file

@ -8,7 +8,7 @@ use activitypub_federation::{config::Data, fetch::object_id::ObjectId};
use lemmy_api_common::context::LemmyContext;
use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult};
use serde::{Deserialize, Serialize};
use strum_macros::Display;
use strum::{Display, IntoStaticStr};
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize)]
@ -22,7 +22,7 @@ pub struct Vote {
pub(crate) audience: Option<ObjectId<ApubCommunity>>,
}
#[derive(Clone, Debug, Display, Deserialize, Serialize, PartialEq, Eq)]
#[derive(Clone, Debug, Display, IntoStaticStr, Deserialize, Serialize, PartialEq, Eq)]
pub enum VoteType {
Like,
Dislike,

View file

@ -46,7 +46,6 @@ serde = { workspace = true }
serde_with = { workspace = true }
url = { workspace = true }
strum = { workspace = true }
strum_macros = { workspace = true }
serde_json = { workspace = true, optional = true }
activitypub_federation = { workspace = true, optional = true }
lemmy_utils = { workspace = true, optional = true }

View file

@ -48,12 +48,12 @@ pub mod utils;
mod schema_setup;
use serde::{Deserialize, Serialize};
use strum_macros::{Display, EnumString};
use strum::{Display, EnumString, IntoStaticStr};
#[cfg(feature = "full")]
use ts_rs::TS;
#[derive(
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
EnumString, IntoStaticStr, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
)]
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
#[cfg_attr(
@ -87,7 +87,7 @@ pub enum SortType {
Scaled,
}
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(EnumString, Display, IntoStaticStr, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The comment sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
@ -100,7 +100,7 @@ pub enum CommentSortType {
}
#[derive(
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
EnumString, Display, IntoStaticStr, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
)]
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
#[cfg_attr(
@ -123,7 +123,7 @@ pub enum ListingType {
}
#[derive(
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
EnumString, Display, IntoStaticStr, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
)]
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
#[cfg_attr(
@ -144,7 +144,7 @@ pub enum RegistrationMode {
}
#[derive(
EnumString, Display, Debug, Serialize, Deserialize, Default, Clone, Copy, PartialEq, Eq, Hash,
EnumString, Display, IntoStaticStr, Debug, Serialize, Deserialize, Default, Clone, Copy, PartialEq, Eq, Hash,
)]
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
#[cfg_attr(
@ -164,7 +164,7 @@ pub enum PostListingMode {
SmallCard,
}
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(EnumString, Display, IntoStaticStr, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The type of content returned from a search.
@ -177,7 +177,7 @@ pub enum SearchType {
Url,
}
#[derive(EnumString, Display, Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy, Hash)]
#[derive(EnumString, Display, IntoStaticStr, Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// A type / status for a community subscribe.
@ -187,7 +187,7 @@ pub enum SubscribedType {
Pending,
}
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(EnumString, Display, IntoStaticStr, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// A list of possible types for the various modlog actions.
@ -211,7 +211,7 @@ pub enum ModlogActionType {
}
#[derive(
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash,
EnumString, Display, IntoStaticStr, Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash,
)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
@ -225,7 +225,7 @@ pub enum PostFeatureType {
}
#[derive(
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
EnumString, Display, IntoStaticStr, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
)]
#[cfg_attr(feature = "full", derive(DbEnum, TS))]
#[cfg_attr(

View file

@ -33,7 +33,6 @@ serde_with = { workspace = true }
ts-rs = { workspace = true, optional = true }
chrono.workspace = true
strum = { workspace = true }
strum_macros = { workspace = true }
[dev-dependencies]
serial_test = { workspace = true }

View file

@ -27,7 +27,7 @@ use lemmy_db_schema::{
SortType,
};
use serde::{Deserialize, Serialize};
use strum_macros::{Display, EnumString};
use strum::{Display, EnumString, IntoStaticStr};
enum ListMode {
Admins,
@ -35,7 +35,7 @@ enum ListMode {
Query(PersonQuery),
}
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
#[derive(EnumString, Display, IntoStaticStr, Debug, Serialize, Deserialize, Clone, Copy)]
/// The person sort types. Converted automatically from `SortType`
enum PersonSortType {
New,

View file

@ -172,7 +172,7 @@ async fn get_feed_data(
let mut channel = Channel {
namespaces: RSS_NAMESPACE.clone(),
title: format!("{} - {}", site_view.site.name, listing_type),
title: format!("{} - {}", site_view.site.name, Into::<&'static str>::into(listing_type)),
link: context.settings().get_protocol_and_hostname(),
items,
..Default::default()

View file

@ -64,7 +64,6 @@ actix-web = { workspace = true, optional = true }
anyhow = { workspace = true, optional = true }
reqwest-middleware = { workspace = true, optional = true }
strum = { workspace = true }
strum_macros = { workspace = true }
futures = { workspace = true, optional = true }
diesel = { workspace = true, features = ["chrono"], optional = true }
http = { workspace = true, optional = true }

View file

@ -1,7 +1,7 @@
use cfg_if::cfg_if;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use strum_macros::{Display, EnumIter};
use strum::{Display, EnumIter};
#[derive(Display, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, EnumIter, Hash)]
#[cfg_attr(feature = "full", derive(ts_rs::TS))]

View file

@ -6,7 +6,7 @@ use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr},
time::Instant,
};
use strum_macros::AsRefStr;
use strum::{Display, IntoStaticStr};
use tracing::debug;
static START_TIME: Lazy<Instant> = Lazy::new(Instant::now);
@ -66,7 +66,7 @@ impl Bucket {
}
}
#[derive(Debug, enum_map::Enum, Copy, Clone, AsRefStr)]
#[derive(Debug, enum_map::Enum, Copy, Clone, Display, IntoStaticStr)]
pub enum ActionType {
Message,
Register,