use std::{fmt, ops};
use crate::param::ParameterId;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Role {
Client = 0,
Server = 1,
}
impl fmt::Display for Role {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad(match *self {
Self::Client => "client",
Self::Server => "server",
})
}
}
impl ops::Not for Role {
type Output = Self;
fn not(self) -> Self {
match self {
Self::Client => Self::Server,
Self::Server => Self::Client,
}
}
}
pub trait IntoRole {
fn into_role() -> Role;
}
pub trait RequiredParameters {
fn required_parameters() -> impl IntoIterator<Item = ParameterId>;
}
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
pub struct Client;
impl From<Client> for Role {
fn from(_: Client) -> Self {
Role::Client
}
}
impl IntoRole for Client {
fn into_role() -> Role {
Role::Client
}
}
impl RequiredParameters for Client {
fn required_parameters() -> impl IntoIterator<Item = ParameterId> {
[ParameterId::InitialSourceConnectionId].into_iter()
}
}
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
pub struct Server;
impl From<Server> for Role {
fn from(_: Server) -> Self {
Role::Server
}
}
impl IntoRole for Server {
fn into_role() -> Role {
Role::Server
}
}
impl RequiredParameters for Server {
fn required_parameters() -> impl IntoIterator<Item = ParameterId> {
[
ParameterId::InitialSourceConnectionId,
ParameterId::OriginalDestinationConnectionId,
]
.into_iter()
}
}