refactor: Use regular functions rather than FromStr impls (#8178)

Implementing `FromStr` and then calling `parse()` creates an
indirection, which is hard to follow for people who are not familiar
with Rust. @r10s recently voiced this problem when we were
pair-programming, and I agree.

We can decide what exactly to call the new function.

I didn't remove all `FromStr` implementations yet; `FromStr for
Fingerprint`, `FromStr for Params`, `FromStr for MozConfigTag` and
`FromStr for EphemeralTimer` are still left.
This commit is contained in:
Hocuri
2026-04-27 11:09:01 +02:00
committed by GitHub
parent 63f96d9138
commit 0580056b62
4 changed files with 34 additions and 42 deletions

View File

@@ -3,6 +3,7 @@
use std::cmp;
use std::collections::{BTreeMap, BTreeSet};
use std::iter;
use std::str::FromStr as _;
use std::sync::LazyLock;
use anyhow::{Context as _, Result, ensure};
@@ -1828,7 +1829,7 @@ async fn add_parts(
// Extract ephemeral timer from the message
let mut ephemeral_timer = if let Some(value) = mime_parser.get_header(HeaderDef::EphemeralTimer)
{
match value.parse::<EphemeralTimer>() {
match EphemeralTimer::from_str(value) {
Ok(timer) => timer,
Err(err) => {
warn!(context, "Can't parse ephemeral timer \"{value}\": {err:#}.");
@@ -2106,7 +2107,7 @@ async fn add_parts(
chat_id,
from_id,
sort_timestamp,
Reaction::from(reaction_str.as_str()),
Reaction::new(reaction_str.as_str()),
is_incoming_fresh,
)
.await?;