use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)]
pub enum RTCIceTransportPolicy {
Unspecified = 0,
#[serde(rename = "all")]
All = 1,
#[serde(rename = "relay")]
Relay = 2,
}
impl Default for RTCIceTransportPolicy {
fn default() -> Self {
RTCIceTransportPolicy::Unspecified
}
}
pub type ICEGatherPolicy = RTCIceTransportPolicy;
const ICE_TRANSPORT_POLICY_RELAY_STR: &str = "relay";
const ICE_TRANSPORT_POLICY_ALL_STR: &str = "all";
impl From<&str> for RTCIceTransportPolicy {
fn from(raw: &str) -> Self {
match raw {
ICE_TRANSPORT_POLICY_RELAY_STR => RTCIceTransportPolicy::Relay,
ICE_TRANSPORT_POLICY_ALL_STR => RTCIceTransportPolicy::All,
_ => RTCIceTransportPolicy::Unspecified,
}
}
}
impl fmt::Display for RTCIceTransportPolicy {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match *self {
RTCIceTransportPolicy::Relay => ICE_TRANSPORT_POLICY_RELAY_STR,
RTCIceTransportPolicy::All => ICE_TRANSPORT_POLICY_ALL_STR,
RTCIceTransportPolicy::Unspecified => crate::UNSPECIFIED_STR,
};
write!(f, "{}", s)
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_new_ice_transport_policy() {
let tests = vec![
("relay", RTCIceTransportPolicy::Relay),
("all", RTCIceTransportPolicy::All),
];
for (policy_string, expected_policy) in tests {
assert_eq!(expected_policy, RTCIceTransportPolicy::from(policy_string));
}
}
#[test]
fn test_ice_transport_policy_string() {
let tests = vec![
(RTCIceTransportPolicy::Relay, "relay"),
(RTCIceTransportPolicy::All, "all"),
];
for (policy, expected_string) in tests {
assert_eq!(expected_string, policy.to_string());
}
}
}