From 696458657b26032e6e2a987c059fd69aaa10508d Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 19 Sep 2022 17:08:01 +0300 Subject: kittybox-indieauth: Allow converting more types to/from strings Sometimes it is needed, for example, to construct an HTML form pre-filled with the request data. --- kittybox-rs/indieauth/src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'kittybox-rs/indieauth/src/lib.rs') diff --git a/kittybox-rs/indieauth/src/lib.rs b/kittybox-rs/indieauth/src/lib.rs index 745ee1e..2cce1b9 100644 --- a/kittybox-rs/indieauth/src/lib.rs +++ b/kittybox-rs/indieauth/src/lib.rs @@ -70,6 +70,15 @@ pub enum ResponseType { /// requested. Code } +// TODO serde_variant +impl ResponseType { + /// Return the response type as it would appear in serialized form. + pub fn as_str(&self) -> &'static str { + match self { + ResponseType::Code => "code", + } + } +} /// Grant types that are described in the IndieAuth spec. /// @@ -252,6 +261,11 @@ impl State { Self(String::from_utf8(bytes).unwrap()) } } +impl AsRef for State { + fn as_ref(&self) -> &str { + self.0.as_str() + } +} /// The authorization request that should be affixed to the URL of an /// authorization endpoint to start the IndieAuth ceremony. -- cgit 1.4.1