2 extern crate lazy_static;
4 extern crate strum_macros;
6 extern crate smart_default;
20 use crate::settings::structs::Settings;
26 pub type ConnectionId = usize;
28 #[derive(PartialEq, Eq, Hash, Debug, Clone)]
29 pub struct IpAddr(pub String);
31 impl fmt::Display for IpAddr {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 write!(f, "{}", self.0)
38 macro_rules! location_info {
41 "None value at {}:{}, column {}",
49 #[derive(Debug, Error)]
50 #[error("{{\"error\":\"{message}\"}}")]
56 pub fn err(msg: &str) -> Self {
58 message: msg.to_string(),
64 pub struct LemmyError {
65 pub inner: anyhow::Error,
68 impl<T> From<T> for LemmyError
70 T: Into<anyhow::Error>,
72 fn from(t: T) -> Self {
73 LemmyError { inner: t.into() }
77 impl std::fmt::Display for LemmyError {
78 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
83 impl actix_web::error::ResponseError for LemmyError {
84 fn status_code(&self) -> StatusCode {
85 match self.inner.downcast_ref::<diesel::result::Error>() {
86 Some(diesel::result::Error::NotFound) => StatusCode::NOT_FOUND,
87 _ => StatusCode::INTERNAL_SERVER_ERROR,
93 pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
94 "^group:([a-z0-9_]{{3,}})@{}$",
95 Settings::get().hostname
97 .expect("compile webfinger regex");
98 pub static ref WEBFINGER_USERNAME_REGEX: Regex = Regex::new(&format!(
99 "^acct:([a-z0-9_]{{3,}})@{}$",
100 Settings::get().hostname
102 .expect("compile webfinger regex");