47 lines
1.2 KiB
Rust
47 lines
1.2 KiB
Rust
|
|
pub mod eds;
|
||
|
|
pub use eds::EDSContactResolverBackend;
|
||
|
|
|
||
|
|
pub trait ContactResolverBackend {
|
||
|
|
type ContactID;
|
||
|
|
|
||
|
|
fn resolve_contact_id(&self, address: &str) -> Option<Self::ContactID>;
|
||
|
|
fn get_contact_display_name(&self, contact_id: &Self::ContactID) -> Option<String>;
|
||
|
|
}
|
||
|
|
|
||
|
|
pub type AnyContactID = String;
|
||
|
|
|
||
|
|
pub struct ContactResolver<T: ContactResolverBackend> {
|
||
|
|
backend: T,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl<T: ContactResolverBackend> ContactResolver<T>
|
||
|
|
where
|
||
|
|
T::ContactID: From<AnyContactID>,
|
||
|
|
T::ContactID: Into<AnyContactID>,
|
||
|
|
T: Default,
|
||
|
|
{
|
||
|
|
pub fn new(backend: T) -> Self {
|
||
|
|
Self { backend }
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn resolve_contact_id(&self, address: &str) -> Option<AnyContactID> {
|
||
|
|
self.backend.resolve_contact_id(address).map(|id| id.into())
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn get_contact_display_name(&self, contact_id: &AnyContactID) -> Option<String> {
|
||
|
|
let backend_contact_id: T::ContactID = T::ContactID::from((*contact_id).clone());
|
||
|
|
self.backend.get_contact_display_name(&backend_contact_id)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl<T: ContactResolverBackend> Default for ContactResolver<T>
|
||
|
|
where
|
||
|
|
T::ContactID: From<AnyContactID>,
|
||
|
|
T::ContactID: Into<AnyContactID>,
|
||
|
|
T: Default,
|
||
|
|
{
|
||
|
|
fn default() -> Self {
|
||
|
|
Self::new(T::default())
|
||
|
|
}
|
||
|
|
}
|