From 5ee84427bf839290afb62e1927ef121b840168d7 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 15 Jan 2023 07:33:09 +0900 Subject: [PATCH] Add functions to make FQN to Fqn --- plume-models/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plume-models/src/lib.rs b/plume-models/src/lib.rs index 83c2b5a3..7e424da8 100644 --- a/plume-models/src/lib.rs +++ b/plume-models/src/lib.rs @@ -20,6 +20,7 @@ use activitystreams::iri_string; use diesel::backend::Backend; use diesel::sql_types::Text; use diesel::types::{FromSql, ToSql}; +use heck::ToUpperCamelCase; pub use lettre; pub use lettre::smtp; use once_cell::sync::Lazy; @@ -358,6 +359,21 @@ impl Fqn { domain, )) } + + pub fn make_local_string(base: &str) -> String { + base.to_upper_camel_case() + .chars() + .filter(|c| c.is_ascii_alphanumeric()) + .collect() + } + + pub fn make_local(base: &str) -> Result { + Self::new_local(Self::make_local_string(base)) + } + + pub fn make_remote(base: &str, domain: String) -> Result { + Self::new_remote(Self::make_local_string(base), domain) + } } impl From<&Fqn> for String {