diff --git a/packages/backend-rs/src/config/server.rs b/packages/backend-rs/src/config/server.rs index 81f2baedb0..19f4d19da0 100644 --- a/packages/backend-rs/src/config/server.rs +++ b/packages/backend-rs/src/config/server.rs @@ -346,7 +346,7 @@ pub fn load_config() -> Config { hostname, redis_key_prefix, scheme, - ws_scheme: ws_scheme.to_string(), + ws_scheme: ws_scheme.to_owned(), } } diff --git a/packages/backend-rs/src/database/cache.rs b/packages/backend-rs/src/database/cache.rs index 60abea56e8..515053ef6c 100644 --- a/packages/backend-rs/src/database/cache.rs +++ b/packages/backend-rs/src/database/cache.rs @@ -62,7 +62,7 @@ fn wildcard(category: Category) -> String { /// # use backend_rs::database::cache; /// # async fn f() -> Result<(), Box> { /// let key = "apple"; -/// let data = "I want to cache this string".to_string(); +/// let data = "I want to cache this string".to_owned(); /// /// // caches the data for 10 seconds /// cache::set(key, &data, 10).await?; @@ -106,7 +106,7 @@ pub async fn set Deserialize<'a> + Serialize>( /// # use backend_rs::database::cache; /// # async fn f() -> Result<(), Box> { /// let key = "banana"; -/// let data = "I want to cache this string".to_string(); +/// let data = "I want to cache this string".to_owned(); /// /// // set cache /// cache::set(key, &data, 10).await?; @@ -145,7 +145,7 @@ pub async fn get Deserialize<'a> + Serialize>(key: &str) -> Result Result<(), Box> { /// let key = "chocolate"; -/// let value = "I want to cache this string".to_string(); +/// let value = "I want to cache this string".to_owned(); /// /// // set cache /// cache::set(key, &value, 10).await?; @@ -248,12 +248,12 @@ mod unit_test { let value_1: Vec = vec![1, 2, 3, 4, 5]; let key_2 = "CARGO_TEST_CACHE_KEY_2"; - let value_2 = "Hello fedizens".to_string(); + let value_2 = "Hello fedizens".to_owned(); let key_3 = "CARGO_TEST_CACHE_KEY_3"; let value_3 = Data { id: 1000000007, - kind: "prime number".to_string(), + kind: "prime number".to_owned(), }; set(key_1, &value_1, 1).await.unwrap(); @@ -287,7 +287,7 @@ mod unit_test { let key_2 = "fish"; let key_3 = "awawa"; - let value_1 = "hello".to_string(); + let value_1 = "hello".to_owned(); let value_2 = 998244353u32; let value_3 = 'あ'; diff --git a/packages/backend-rs/src/database/redis.rs b/packages/backend-rs/src/database/redis.rs index a0fc16eea6..7fa7255b47 100644 --- a/packages/backend-rs/src/database/redis.rs +++ b/packages/backend-rs/src/database/redis.rs @@ -57,12 +57,12 @@ async fn init_conn_pool() -> Result<(), RedisError> { }; if let Some(user) = &redis.user { - params.push(user.to_string()) + params.push(user.to_owned()) } if let Some(pass) = &redis.pass { params.push(format!(":{}@", urlencoding::encode(pass))) } - params.push(redis.host.to_string()); + params.push(redis.host.to_owned()); params.push(format!(":{}", redis.port)); params.push(format!("/{}", redis.db)); @@ -111,8 +111,8 @@ pub async fn get_conn() -> Result String { - format!("{}:{}", CONFIG.redis_key_prefix, key.to_string()) +pub fn key(key: impl std::fmt::Display) -> String { + format!("{}:{}", CONFIG.redis_key_prefix, key) } #[cfg(test)] diff --git a/packages/backend-rs/src/federation/acct.rs b/packages/backend-rs/src/federation/acct.rs index 60c9e6f25c..1c28685cd8 100644 --- a/packages/backend-rs/src/federation/acct.rs +++ b/packages/backend-rs/src/federation/acct.rs @@ -25,11 +25,11 @@ impl FromStr for Acct { .collect(); Ok(Self { - username: split[0].to_string(), + username: split[0].to_owned(), host: if split.len() == 1 { None } else { - Some(split[1].to_string()) + Some(split[1].to_owned()) }, }) } @@ -70,11 +70,11 @@ mod unit_test { #[test] fn acct_to_string() { let remote_acct = Acct { - username: "firefish".to_string(), - host: Some("example.com".to_string()), + username: "firefish".to_owned(), + host: Some("example.com".to_owned()), }; let local_acct = Acct { - username: "MisakaMikoto".to_string(), + username: "MisakaMikoto".to_owned(), host: None, }; @@ -87,11 +87,11 @@ mod unit_test { #[test] fn string_to_acct() { let remote_acct = Acct { - username: "firefish".to_string(), - host: Some("example.com".to_string()), + username: "firefish".to_owned(), + host: Some("example.com".to_owned()), }; let local_acct = Acct { - username: "MisakaMikoto".to_string(), + username: "MisakaMikoto".to_owned(), host: None, }; diff --git a/packages/backend-rs/src/federation/nodeinfo/fetch.rs b/packages/backend-rs/src/federation/nodeinfo/fetch.rs index 4f11821054..c237a893fb 100644 --- a/packages/backend-rs/src/federation/nodeinfo/fetch.rs +++ b/packages/backend-rs/src/federation/nodeinfo/fetch.rs @@ -109,12 +109,12 @@ mod unit_test { let links_1 = NodeinfoLinks { links: vec![ NodeinfoLink { - rel: "https://example.com/incorrect/schema/2.0".to_string(), - href: "https://example.com/dummy".to_string(), + rel: "https://example.com/incorrect/schema/2.0".to_owned(), + href: "https://example.com/dummy".to_owned(), }, NodeinfoLink { - rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_string(), - href: "https://example.com/real".to_string(), + rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_owned(), + href: "https://example.com/real".to_owned(), }, ], }; @@ -126,12 +126,12 @@ mod unit_test { let links_2 = NodeinfoLinks { links: vec![ NodeinfoLink { - rel: "https://example.com/incorrect/schema/2.0".to_string(), - href: "https://example.com/dummy".to_string(), + rel: "https://example.com/incorrect/schema/2.0".to_owned(), + href: "https://example.com/dummy".to_owned(), }, NodeinfoLink { - rel: "http://nodeinfo.diaspora.software/ns/schema/2.1".to_string(), - href: "https://example.com/real".to_string(), + rel: "http://nodeinfo.diaspora.software/ns/schema/2.1".to_owned(), + href: "https://example.com/real".to_owned(), }, ], }; @@ -143,12 +143,12 @@ mod unit_test { let links_3 = NodeinfoLinks { links: vec![ NodeinfoLink { - rel: "https://example.com/incorrect/schema/2.0".to_string(), - href: "https://example.com/dummy/2.0".to_string(), + rel: "https://example.com/incorrect/schema/2.0".to_owned(), + href: "https://example.com/dummy/2.0".to_owned(), }, NodeinfoLink { - rel: "https://example.com/incorrect/schema/2.1".to_string(), - href: "https://example.com/dummy/2.1".to_string(), + rel: "https://example.com/incorrect/schema/2.1".to_owned(), + href: "https://example.com/dummy/2.1".to_owned(), }, ], }; diff --git a/packages/backend-rs/src/federation/nodeinfo/generate.rs b/packages/backend-rs/src/federation/nodeinfo/generate.rs index 80fe4bc609..c74fd55e10 100644 --- a/packages/backend-rs/src/federation/nodeinfo/generate.rs +++ b/packages/backend-rs/src/federation/nodeinfo/generate.rs @@ -68,45 +68,45 @@ async fn generate_nodeinfo_2_1() -> Result { let meta = local_server_info().await?; let mut metadata = HashMap::from([ ( - "nodeName".to_string(), + "nodeName".to_owned(), json!(meta.name.unwrap_or_else(|| CONFIG.host.clone())), ), - ("nodeDescription".to_string(), json!(meta.description)), - ("repositoryUrl".to_string(), json!(meta.repository_url)), + ("nodeDescription".to_owned(), json!(meta.description)), + ("repositoryUrl".to_owned(), json!(meta.repository_url)), ( - "enableLocalTimeline".to_string(), + "enableLocalTimeline".to_owned(), json!(!meta.disable_local_timeline), ), ( - "enableRecommendedTimeline".to_string(), + "enableRecommendedTimeline".to_owned(), json!(!meta.disable_recommended_timeline), ), ( - "enableGlobalTimeline".to_string(), + "enableGlobalTimeline".to_owned(), json!(!meta.disable_global_timeline), ), ( - "enableGuestTimeline".to_string(), + "enableGuestTimeline".to_owned(), json!(meta.enable_guest_timeline), ), ( - "maintainer".to_string(), + "maintainer".to_owned(), json!({"name":meta.maintainer_name,"email":meta.maintainer_email}), ), - ("proxyAccountName".to_string(), json!(meta.proxy_account_id)), + ("proxyAccountName".to_owned(), json!(meta.proxy_account_id)), ( - "themeColor".to_string(), - json!(meta.theme_color.unwrap_or_else(|| "#31748f".to_string())), + "themeColor".to_owned(), + json!(meta.theme_color.unwrap_or_else(|| "#31748f".to_owned())), ), ]); metadata.shrink_to_fit(); Ok(Nodeinfo21 { software: Software21 { - name: "firefish".to_string(), + name: "firefish".to_owned(), version: CONFIG.version.clone(), repository: Some(meta.repository_url), - homepage: Some("https://firefish.dev/firefish/firefish".to_string()), + homepage: Some("https://firefish.dev/firefish/firefish".to_owned()), }, protocols: vec![Protocol::Activitypub], services: Services { diff --git a/packages/backend-rs/src/init/log.rs b/packages/backend-rs/src/init/log.rs index 47466735e3..a1dab991a4 100644 --- a/packages/backend-rs/src/init/log.rs +++ b/packages/backend-rs/src/init/log.rs @@ -18,15 +18,15 @@ pub fn initialize_logger() { }); } else if let Some(levels) = &CONFIG.log_level { // `logLevel` config is Deprecated - if levels.contains(&"trace".to_string()) { + if levels.contains(&"trace".to_owned()) { builder = builder.with_max_level(Level::TRACE); - } else if levels.contains(&"debug".to_string()) { + } else if levels.contains(&"debug".to_owned()) { builder = builder.with_max_level(Level::DEBUG); - } else if levels.contains(&"info".to_string()) { + } else if levels.contains(&"info".to_owned()) { builder = builder.with_max_level(Level::INFO); - } else if levels.contains(&"warning".to_string()) { + } else if levels.contains(&"warning".to_owned()) { builder = builder.with_max_level(Level::WARN); - } else if levels.contains(&"error".to_string()) { + } else if levels.contains(&"error".to_owned()) { builder = builder.with_max_level(Level::ERROR); } else { // Fallback diff --git a/packages/backend-rs/src/init/system_info.rs b/packages/backend-rs/src/init/system_info.rs index 7fde335e85..82505a1625 100644 --- a/packages/backend-rs/src/init/system_info.rs +++ b/packages/backend-rs/src/init/system_info.rs @@ -26,19 +26,19 @@ pub fn show_server_info() -> Result<(), SysinfoPoisonError> { tracing::info!( "Hostname: {}", - System::host_name().unwrap_or_else(|| "unknown".to_string()) + System::host_name().unwrap_or_else(|| "unknown".to_owned()) ); tracing::info!( "OS: {}", - System::long_os_version().unwrap_or_else(|| "unknown".to_string()) + System::long_os_version().unwrap_or_else(|| "unknown".to_owned()) ); tracing::info!( "Kernel: {}", - System::kernel_version().unwrap_or_else(|| "unknown".to_string()) + System::kernel_version().unwrap_or_else(|| "unknown".to_owned()) ); tracing::info!( "CPU architecture: {}", - System::cpu_arch().unwrap_or_else(|| "unknown".to_string()) + System::cpu_arch().unwrap_or_else(|| "unknown".to_owned()) ); tracing::info!("CPU threads: {}", system_info.cpus().len()); tracing::info!("Total memory: {} MiB", system_info.total_memory() / 1048576); diff --git a/packages/backend-rs/src/misc/check_server_block.rs b/packages/backend-rs/src/misc/check_server_block.rs index a6355f5e94..ecc50132ad 100644 --- a/packages/backend-rs/src/misc/check_server_block.rs +++ b/packages/backend-rs/src/misc/check_server_block.rs @@ -81,7 +81,7 @@ pub async fn is_allowed_server(host: &str) -> Result { return Ok(true); } if let Some(allowed_hosts) = meta.allowed_hosts { - return Ok(allowed_hosts.contains(&host.to_string())); + return Ok(allowed_hosts.contains(&host.to_owned())); } Ok(false) } diff --git a/packages/backend-rs/src/misc/check_word_mute.rs b/packages/backend-rs/src/misc/check_word_mute.rs index fdf4e1a8a0..f4f2e1234a 100644 --- a/packages/backend-rs/src/misc/check_word_mute.rs +++ b/packages/backend-rs/src/misc/check_word_mute.rs @@ -73,114 +73,114 @@ mod unit_test { #[test] fn word_mute_match() { let texts = [ - "The quick brown fox jumps over the lazy dog.".to_string(), - "色は匂へど 散りぬるを 我が世誰ぞ 常ならむ".to_string(), - "😇".to_string(), + "The quick brown fox jumps over the lazy dog.".to_owned(), + "色は匂へど 散りぬるを 我が世誰ぞ 常ならむ".to_owned(), + "😇".to_owned(), ]; - let hiragana_1 = r"/[\u{3040}-\u{309f}]/u".to_string(); - let hiragana_2 = r"/[あ-ん]/u".to_string(); - let katakana_1 = r"/[\u{30a1}-\u{30ff}]/u".to_string(); - let katakana_2 = r"/[ア-ン]/u".to_string(); - let emoji = r"/[\u{1f300}-\u{1f5ff}\u{1f900}-\u{1f9ff}\u{1f600}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{2600}-\u{26ff}\u{2700}-\u{27bf}\u{1f1e6}-\u{1f1ff}\u{1f191}-\u{1f251}\u{1f004}\u{1f0cf}\u{1f170}-\u{1f171}\u{1f17e}-\u{1f17f}\u{1f18e}\u{3030}\u{2b50}\u{2b55}\u{2934}-\u{2935}\u{2b05}-\u{2b07}\u{2b1b}-\u{2b1c}\u{3297}\u{3299}\u{303d}\u{00a9}\u{00ae}\u{2122}\u{23f3}\u{24c2}\u{23e9}-\u{23ef}\u{25b6}\u{23f8}-\u{23fa}]/u".to_string(); + let hiragana_1 = r"/[\u{3040}-\u{309f}]/u".to_owned(); + let hiragana_2 = r"/[あ-ん]/u".to_owned(); + let katakana_1 = r"/[\u{30a1}-\u{30ff}]/u".to_owned(); + let katakana_2 = r"/[ア-ン]/u".to_owned(); + let emoji = r"/[\u{1f300}-\u{1f5ff}\u{1f900}-\u{1f9ff}\u{1f600}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{2600}-\u{26ff}\u{2700}-\u{27bf}\u{1f1e6}-\u{1f1ff}\u{1f191}-\u{1f251}\u{1f004}\u{1f0cf}\u{1f170}-\u{1f171}\u{1f17e}-\u{1f17f}\u{1f18e}\u{3030}\u{2b50}\u{2b55}\u{2934}-\u{2935}\u{2b05}-\u{2b07}\u{2b1b}-\u{2b1c}\u{3297}\u{3299}\u{303d}\u{00a9}\u{00ae}\u{2122}\u{23f3}\u{24c2}\u{23e9}-\u{23ef}\u{25b6}\u{23f8}-\u{23fa}]/u".to_owned(); - assert!(check_word_mute_impl(&texts, &[], &["/the/i".to_string()])); + assert!(check_word_mute_impl(&texts, &[], &["/the/i".to_owned()])); - assert!(!check_word_mute_impl(&texts, &[], &["/the/".to_string()])); + assert!(!check_word_mute_impl(&texts, &[], &["/the/".to_owned()])); - assert!(check_word_mute_impl(&texts, &[], &["/QuICk/i".to_string()])); + assert!(check_word_mute_impl(&texts, &[], &["/QuICk/i".to_owned()])); - assert!(!check_word_mute_impl(&texts, &[], &["/QuICk/".to_string()])); + assert!(!check_word_mute_impl(&texts, &[], &["/QuICk/".to_owned()])); assert!(check_word_mute_impl( &texts, &[ - "我".to_string(), - "有為の奥山 今日越えて 浅き夢見し 酔ひもせず".to_string() + "我".to_owned(), + "有為の奥山 今日越えて 浅き夢見し 酔ひもせず".to_owned() ], &[] )); assert!(!check_word_mute_impl( &texts, - &["有為の奥山 今日越えて 浅き夢見し 酔ひもせず".to_string()], + &["有為の奥山 今日越えて 浅き夢見し 酔ひもせず".to_owned()], &[] )); assert!(!check_word_mute_impl( &texts, &[ - "有為の奥山".to_string(), - "今日越えて".to_string(), - "浅き夢見し".to_string(), - "酔ひもせず".to_string() + "有為の奥山".to_owned(), + "今日越えて".to_owned(), + "浅き夢見し".to_owned(), + "酔ひもせず".to_owned() ], &[] )); assert!(check_word_mute_impl( &texts, - &["yellow fox".to_string(), "mastodon".to_string()], + &["yellow fox".to_owned(), "mastodon".to_owned()], &[hiragana_1.clone()] )); assert!(check_word_mute_impl( &texts, - &["yellow fox".to_string(), "mastodon".to_string()], + &["yellow fox".to_owned(), "mastodon".to_owned()], &[hiragana_2.clone()] )); assert!(!check_word_mute_impl( &texts, - &["yellow fox".to_string(), "mastodon".to_string()], + &["yellow fox".to_owned(), "mastodon".to_owned()], &[katakana_1.clone()] )); assert!(!check_word_mute_impl( &texts, - &["yellow fox".to_string(), "mastodon".to_string()], + &["yellow fox".to_owned(), "mastodon".to_owned()], &[katakana_2.clone()] )); assert!(check_word_mute_impl( &texts, - &["brown fox".to_string(), "mastodon".to_string()], + &["brown fox".to_owned(), "mastodon".to_owned()], &[katakana_1.clone()] )); assert!(check_word_mute_impl( &texts, - &["brown fox".to_string(), "mastodon".to_string()], + &["brown fox".to_owned(), "mastodon".to_owned()], &[katakana_2.clone()] )); assert!(check_word_mute_impl( &texts, - &["yellow fox".to_string(), "dog".to_string()], + &["yellow fox".to_owned(), "dog".to_owned()], &[katakana_1.clone()] )); assert!(check_word_mute_impl( &texts, - &["yellow fox".to_string(), "dog".to_string()], + &["yellow fox".to_owned(), "dog".to_owned()], &[katakana_2.clone()] )); assert!(check_word_mute_impl( &texts, - &["yellow fox".to_string(), "mastodon".to_string()], + &["yellow fox".to_owned(), "mastodon".to_owned()], &[hiragana_1.clone(), katakana_1.clone()] )); assert!(check_word_mute_impl( &texts, - &["😇".to_string(), "🥲".to_string(), "🥴".to_string()], + &["😇".to_owned(), "🥲".to_owned(), "🥴".to_owned()], &[] )); assert!(!check_word_mute_impl( &texts, - &["🙂".to_string(), "🥲".to_string(), "🥴".to_string()], + &["🙂".to_owned(), "🥲".to_owned(), "🥴".to_owned()], &[] )); diff --git a/packages/backend-rs/src/misc/get_image_size.rs b/packages/backend-rs/src/misc/get_image_size.rs index 1964c9cbd9..bc5222f054 100644 --- a/packages/backend-rs/src/misc/get_image_size.rs +++ b/packages/backend-rs/src/misc/get_image_size.rs @@ -68,7 +68,7 @@ pub async fn get_image_size_from_url(url: &str) -> Result { if attempted { tracing::warn!("attempt limit exceeded: {}", url); - return Err(Error::TooManyAttempts(url.to_string())); + return Err(Error::TooManyAttempts(url.to_owned())); } tracing::info!("retrieving image from {}", url); diff --git a/packages/backend-rs/src/misc/note/summarize.rs b/packages/backend-rs/src/misc/note/summarize.rs index 9649fc9345..0a6240d194 100644 --- a/packages/backend-rs/src/misc/note/summarize.rs +++ b/packages/backend-rs/src/misc/note/summarize.rs @@ -15,12 +15,12 @@ pub fn summarize_impl( match file_ids.len() { 0 => (), - 1 => buf.push("📎".to_string()), + 1 => buf.push("📎".to_owned()), n => buf.push(format!("📎 ({})", n)), }; if has_poll { - buf.push("📊".to_string()) + buf.push("📊".to_owned()) } buf.join(" ") @@ -94,7 +94,7 @@ mod unit_test { fn summarize_note() { let note = NoteLike { file_ids: vec![], - text: Some("Hello world!".to_string()), + text: Some("Hello world!".to_owned()), cw: None, has_poll: false, }; @@ -102,26 +102,26 @@ mod unit_test { let note_with_cw = NoteLike { file_ids: vec![], - text: Some("Hello world!".to_string()), - cw: Some("Content warning".to_string()), + text: Some("Hello world!".to_owned()), + cw: Some("Content warning".to_owned()), has_poll: false, }; assert_eq!(summarize!(note_with_cw), "Content warning"); let note_with_file_and_cw = NoteLike { - file_ids: vec!["9s7fmcqogiq4igin".to_string()], + file_ids: vec!["9s7fmcqogiq4igin".to_owned()], text: None, - cw: Some("Selfie, no ec".to_string()), + cw: Some("Selfie, no ec".to_owned()), has_poll: false, }; assert_eq!(summarize!(note_with_file_and_cw), "Selfie, no ec 📎"); let note_with_files_only = NoteLike { file_ids: vec![ - "9s7fmcqogiq4igin".to_string(), - "9s7qrld5u14cey98".to_string(), - "9s7gebs5zgts4kca".to_string(), - "9s5z3e4vefqd29ee".to_string(), + "9s7fmcqogiq4igin".to_owned(), + "9s7qrld5u14cey98".to_owned(), + "9s7gebs5zgts4kca".to_owned(), + "9s5z3e4vefqd29ee".to_owned(), ], text: None, cw: None, @@ -131,13 +131,13 @@ mod unit_test { let note_all = NoteLike { file_ids: vec![ - "9s7fmcqogiq4igin".to_string(), - "9s7qrld5u14cey98".to_string(), - "9s7gebs5zgts4kca".to_string(), - "9s5z3e4vefqd29ee".to_string(), + "9s7fmcqogiq4igin".to_owned(), + "9s7qrld5u14cey98".to_owned(), + "9s7gebs5zgts4kca".to_owned(), + "9s5z3e4vefqd29ee".to_owned(), ], - text: Some("Hello world!".to_string()), - cw: Some("Content warning".to_string()), + text: Some("Hello world!".to_owned()), + cw: Some("Content warning".to_owned()), has_poll: true, }; assert_eq!(summarize!(note_all), "Content warning 📎 (4) 📊"); diff --git a/packages/backend-rs/src/misc/reaction.rs b/packages/backend-rs/src/misc/reaction.rs index 01441b90a3..e6b699d59a 100644 --- a/packages/backend-rs/src/misc/reaction.rs +++ b/packages/backend-rs/src/misc/reaction.rs @@ -128,12 +128,12 @@ mod unit_test { #[test] fn decode_reaction() { let unicode_emoji_1 = DecodedReaction { - reaction: "⭐".to_string(), + reaction: "⭐".to_owned(), name: None, host: None, }; let unicode_emoji_2 = DecodedReaction { - reaction: "🩷".to_string(), + reaction: "🩷".to_owned(), name: None, host: None, }; @@ -145,23 +145,23 @@ mod unit_test { assert_ne!(super::decode_reaction("🩷"), unicode_emoji_1); let unicode_emoji_3 = DecodedReaction { - reaction: "🖖🏿".to_string(), + reaction: "🖖🏿".to_owned(), name: None, host: None, }; assert_eq!(super::decode_reaction("🖖🏿"), unicode_emoji_3); let local_emoji = DecodedReaction { - reaction: ":meow_melt_tears@.:".to_string(), - name: Some("meow_melt_tears".to_string()), + reaction: ":meow_melt_tears@.:".to_owned(), + name: Some("meow_melt_tears".to_owned()), host: None, }; assert_eq!(super::decode_reaction(":meow_melt_tears:"), local_emoji); let remote_emoji_1 = DecodedReaction { - reaction: ":meow_uwu@some-domain.example.org:".to_string(), - name: Some("meow_uwu".to_string()), - host: Some("some-domain.example.org".to_string()), + reaction: ":meow_uwu@some-domain.example.org:".to_owned(), + name: Some("meow_uwu".to_owned()), + host: Some("some-domain.example.org".to_owned()), }; assert_eq!( super::decode_reaction(":meow_uwu@some-domain.example.org:"), @@ -169,9 +169,9 @@ mod unit_test { ); let remote_emoji_2 = DecodedReaction { - reaction: ":C++23@xn--eckwd4c7c.example.org:".to_string(), - name: Some("C++23".to_string()), - host: Some("xn--eckwd4c7c.example.org".to_string()), + reaction: ":C++23@xn--eckwd4c7c.example.org:".to_owned(), + name: Some("C++23".to_owned()), + host: Some("xn--eckwd4c7c.example.org".to_owned()), }; assert_eq!( super::decode_reaction(":C++23@xn--eckwd4c7c.example.org:"), @@ -179,14 +179,14 @@ mod unit_test { ); let invalid_reaction_1 = DecodedReaction { - reaction: ":foo".to_string(), + reaction: ":foo".to_owned(), name: None, host: None, }; assert_eq!(super::decode_reaction(":foo"), invalid_reaction_1); let invalid_reaction_2 = DecodedReaction { - reaction: ":foo&@example.com:".to_string(), + reaction: ":foo&@example.com:".to_owned(), name: None, host: None, }; diff --git a/packages/backend-rs/src/misc/system_info.rs b/packages/backend-rs/src/misc/system_info.rs index 4b31ceaaee..d5191c16f6 100644 --- a/packages/backend-rs/src/misc/system_info.rs +++ b/packages/backend-rs/src/misc/system_info.rs @@ -38,9 +38,9 @@ pub fn cpu_info() -> Result { model: match system_info.cpus() { [] => { tracing::debug!("failed to get CPU info"); - "unknown".to_string() + "unknown".to_owned() } - cpus => cpus[0].brand().to_string(), + cpus => cpus[0].brand().to_owned(), }, cores: system_info.cpus().len() as u16, }) diff --git a/packages/backend-rs/src/service/antenna/process_new_note.rs b/packages/backend-rs/src/service/antenna/process_new_note.rs index 13fc7fdcbb..0588c3c3f3 100644 --- a/packages/backend-rs/src/service/antenna/process_new_note.rs +++ b/packages/backend-rs/src/service/antenna/process_new_note.rs @@ -71,7 +71,7 @@ async fn add_note_to_antenna(antenna_id: &str, note: &Note) -> Result<(), Error> .await?; // for streaming API - stream::antenna::publish(antenna_id.to_string(), note).await?; + stream::antenna::publish(antenna_id.to_owned(), note).await?; Ok(()) } diff --git a/packages/backend-rs/src/service/note/watch.rs b/packages/backend-rs/src/service/note/watch.rs index 144f4e2360..3a5e9a0bf3 100644 --- a/packages/backend-rs/src/service/note/watch.rs +++ b/packages/backend-rs/src/service/note/watch.rs @@ -13,9 +13,9 @@ pub async fn watch_note( note_watching::Entity::insert(note_watching::ActiveModel { id: ActiveValue::set(gen_id_at(now)), created_at: ActiveValue::set(now.into()), - user_id: ActiveValue::Set(watcher_id.to_string()), - note_user_id: ActiveValue::Set(note_author_id.to_string()), - note_id: ActiveValue::Set(note_id.to_string()), + user_id: ActiveValue::Set(watcher_id.to_owned()), + note_user_id: ActiveValue::Set(note_author_id.to_owned()), + note_id: ActiveValue::Set(note_id.to_owned()), }) .exec(db_conn().await?) .await?; diff --git a/packages/backend-rs/src/service/push_notification.rs b/packages/backend-rs/src/service/push_notification.rs index 6abe5e1866..cfe1d99ae8 100644 --- a/packages/backend-rs/src/service/push_notification.rs +++ b/packages/backend-rs/src/service/push_notification.rs @@ -55,7 +55,7 @@ pub enum PushNotificationKind { fn compact_content(mut content: serde_json::Value) -> Result { if !content.is_object() { - return Err(Error::InvalidContent("not a JSON object".to_string())); + return Err(Error::InvalidContent("not a JSON object".to_owned())); } let object = content.as_object_mut().unwrap(); @@ -69,9 +69,7 @@ fn compact_content(mut content: serde_json::Value) -> Result Result Result Result { let object = content .as_object_mut() - .ok_or(Error::InvalidContent("not a JSON object".to_string()))?; + .ok_or(Error::InvalidContent("not a JSON object".to_owned()))?; if subscription.app_access_token_id.is_none() { unsubscribe(db, &subscription.id).await?; - return Err(Error::InvalidSubscription("no access token".to_string())); + return Err(Error::InvalidSubscription("no access token".to_owned())); } let (token, client_name) = get_mastodon_subscription_info( @@ -166,7 +164,7 @@ async fn encode_mastodon_payload( ) .await?; - object.insert("access_token".to_string(), serde_json::to_value(token)?); + object.insert("access_token".to_owned(), serde_json::to_value(token)?); // Some apps expect notification_id to be an integer, // but doesn’t break when the ID doesn’t match the rest of API. @@ -187,7 +185,7 @@ async fn encode_mastodon_payload( .transpose()? .unwrap_or_default(); - object.insert("notification_id".to_string(), timestamp.into()); + object.insert("notification_id".to_owned(), timestamp.into()); } let res = serde_json::to_string(&content)?; @@ -273,7 +271,7 @@ pub async fn send_push_notification( // TODO: refactoring let mut payload = if use_mastodon_api { // Content generated per subscription - "".to_string() + "".to_owned() } else { // Format the `content` passed from the TypeScript backend // for Firefish push notifications diff --git a/packages/backend-rs/src/service/stream.rs b/packages/backend-rs/src/service/stream.rs index 236f34fcad..25f5802eef 100644 --- a/packages/backend-rs/src/service/stream.rs +++ b/packages/backend-rs/src/service/stream.rs @@ -80,13 +80,13 @@ pub async fn publish_to_stream( value: Option, ) -> Result<(), Error> { let channel = match stream { - Stream::Internal => "internal".to_string(), - Stream::CustomEmoji => "broadcast".to_string(), + Stream::Internal => "internal".to_owned(), + Stream::CustomEmoji => "broadcast".to_owned(), Stream::Moderation { moderator_id } => format!("adminStream:{moderator_id}"), Stream::User { user_id } => format!("user:{user_id}"), Stream::Channel { channel_id } => format!("channelStream:{channel_id}"), Stream::Note { note_id } => format!("noteStream:{note_id}"), - Stream::Notes => "notesStream".to_string(), + Stream::Notes => "notesStream".to_owned(), Stream::UserList { list_id } => format!("userListStream:{list_id}"), Stream::Main { user_id } => format!("mainStream:{user_id}"), Stream::Drive { user_id } => format!("driveStream:{user_id}"), @@ -103,7 +103,7 @@ pub async fn publish_to_stream( format!( "{{\"type\":\"{}\",\"body\":{}}}", kind, - value.unwrap_or_else(|| "null".to_string()), + value.unwrap_or_else(|| "null".to_owned()), ) } else { value.ok_or(Error::InvalidContent)? diff --git a/packages/backend-rs/src/util/error_chain.rs b/packages/backend-rs/src/util/error_chain.rs index 4d1341dc05..d19c99ae76 100644 --- a/packages/backend-rs/src/util/error_chain.rs +++ b/packages/backend-rs/src/util/error_chain.rs @@ -46,7 +46,7 @@ mod unit_test { Err(InnerError1) } fn causes_inner_error_2() -> Result<(), InnerError2> { - Err(InnerError2("foo".to_string())) + Err(InnerError2("foo".to_owned())) } fn causes_error_1() -> Result<(), ErrorVariants> { diff --git a/packages/backend-rs/src/util/id.rs b/packages/backend-rs/src/util/id.rs index c7f5f294dd..4cce5897f0 100644 --- a/packages/backend-rs/src/util/id.rs +++ b/packages/backend-rs/src/util/id.rs @@ -58,7 +58,7 @@ pub fn get_timestamp(id: &str) -> Result { if let Some(n) = n { Ok(n as i64 + TIME_2000) } else { - Err(InvalidIdError { id: id.to_string() }) + Err(InvalidIdError { id: id.to_owned() }) } }