From 31515887deed483ad6fbe44f008451905ac23589 Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Tue, 12 Apr 2022 13:02:34 -0700 Subject: [PATCH] FromStr, Display for UnassignedChannelDataPolicy --- src/client/mod.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/client/mod.rs b/src/client/mod.rs index b55cc93..c720de7 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -441,6 +441,35 @@ impl Default for UnassignedChannelDataPolicy { } } +impl std::fmt::Display for UnassignedChannelDataPolicy { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.pad(match self { + UnassignedChannelDataPolicy::Auto => "auto", + UnassignedChannelDataPolicy::AssumeStaleSession => "assume-stale-session", + UnassignedChannelDataPolicy::Error => "error", + UnassignedChannelDataPolicy::Ignore => "ignore", + }) + } +} + +impl std::str::FromStr for UnassignedChannelDataPolicy { + type Err = Error; + + fn from_str(s: &str) -> Result { + Ok(match s { + "auto" => UnassignedChannelDataPolicy::Auto, + "assume-stale-session" => UnassignedChannelDataPolicy::AssumeStaleSession, + "error" => UnassignedChannelDataPolicy::Error, + "ignore" => UnassignedChannelDataPolicy::Ignore, + _ => bail!(ErrorInt::InvalidArgument(format!( + "bad UnassignedChannelDataPolicy {}; expected auto, assume-stale-session, error, \ + or ignore", + s + ))), + }) + } +} + /// The RTP packet transport to request. /// /// Defaults to `Transport::Tcp`.