use crate::peer::PeerIdentity;
use std::collections::BTreeSet;
pub type Scope = String;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Caller {
LocalApp { app: String, peer: PeerIdentity },
Device { id: String, scopes: BTreeSet<Scope> },
}
impl Caller {
pub fn local_app(app: impl Into<String>, peer: PeerIdentity) -> Self {
Caller::LocalApp {
app: app.into(),
peer,
}
}
pub fn device<I, S>(id: impl Into<String>, scopes: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<Scope>,
{
Caller::Device {
id: id.into(),
scopes: scopes.into_iter().map(Into::into).collect(),
}
}
pub fn peer(&self) -> Option<&PeerIdentity> {
match self {
Caller::LocalApp { peer, .. } => Some(peer),
Caller::Device { .. } => None,
}
}
pub fn label(&self) -> &str {
match self {
Caller::LocalApp { app, .. } => app,
Caller::Device { id, .. } => id,
}
}
}