Skip to content

Commit

Permalink
Implement Display for Id instead of ToString
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksbgbg committed Feb 14, 2024
1 parent f96dfbc commit 64f03f4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions backend-rs/backend/src/models/id.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use sea_orm::{DbErr, DeriveValueType, TryFromU64};
use serde::de::{Unexpected, Visitor};
use serde::{Deserialize, Serialize};
use std::fmt::Formatter;
use std::fmt::{Display, Formatter};

#[derive(Clone, Copy, Debug, PartialEq, Eq, DeriveValueType)]
pub struct Id(i64);
Expand Down Expand Up @@ -38,10 +38,10 @@ fn decode(str: &str) -> Result<Id, bs58::decode::Error> {
Ok(Id::from(i64::from_be_bytes(decoded)))
}

impl ToString for Id {
fn to_string(&self) -> String {
encode(*self).expect("could not encode ID into base 58")
}
impl Display for Id {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", encode(*self).expect("could not encode ID into base 58"))
}
}

impl Serialize for Id {
Expand Down

0 comments on commit 64f03f4

Please sign in to comment.