Skip to main content

stoat/ext/
identifiable.rs

1use std::time::SystemTime;
2
3use crate::created_at;
4
5pub trait Identifiable {
6    fn id(&self) -> &str;
7
8    fn created_at(&self) -> SystemTime {
9        created_at(self.id())
10    }
11}
12
13#[cfg(feature = "either")]
14impl<L: Identifiable, R: Identifiable> Identifiable for either::Either<L, R> {
15    fn id(&self) -> &str {
16        match self {
17            either::Either::Left(l) => l.id(),
18            either::Either::Right(r) => r.id(),
19        }
20    }
21}