mirror of
https://github.com/chatmail/core.git
synced 2026-04-29 11:26:29 +03:00
refactor: Use regular functions rather than FromStr impls
Implementing `FromStr` and then calling `parse()` creates an indirection, which is hard to follow for people who are not familiar with Rust. r10s recently had this problem.
This commit is contained in:
@@ -66,7 +66,6 @@ use std::cmp::max;
|
||||
use std::collections::BTreeSet;
|
||||
use std::fmt;
|
||||
use std::num::ParseIntError;
|
||||
use std::str::FromStr;
|
||||
use std::time::{Duration, UNIX_EPOCH};
|
||||
|
||||
use anyhow::{Context as _, Result, ensure};
|
||||
@@ -124,6 +123,12 @@ impl Timer {
|
||||
Self::Enabled { duration }
|
||||
}
|
||||
}
|
||||
|
||||
/// Tries to parse a string as an integer,
|
||||
/// and converts it to an ephemeral timer value.
|
||||
pub fn from_str(input: &str) -> Result<Timer, ParseIntError> {
|
||||
input.parse::<u32>().map(Self::from_u32)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Timer {
|
||||
@@ -132,14 +137,6 @@ impl fmt::Display for Timer {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Timer {
|
||||
type Err = ParseIntError;
|
||||
|
||||
fn from_str(input: &str) -> Result<Timer, ParseIntError> {
|
||||
input.parse::<u32>().map(Self::from_u32)
|
||||
}
|
||||
}
|
||||
|
||||
impl rusqlite::types::ToSql for Timer {
|
||||
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> {
|
||||
let val = rusqlite::types::Value::Integer(match self {
|
||||
|
||||
Reference in New Issue
Block a user