Enum biscuit::StringOrUri [] [src]

pub enum StringOrUri {
    String(String),
    Uri(Url),
}

Represents a choice between a URI or an arbitrary string. Both variants will serialize to a string. According to RFC 7519, any string containing the ":" character will be deserialized as a URL. Any invalid URLs will be treated as a deserialization failure. The URL is parsed according to the URL Standard which supersedes RFC 3986 as required in the JWT RFC.

Examples

extern crate biscuit;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;

use std::str::FromStr;
use biscuit::{SingleOrMultiple, StringOrUri};

#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
struct SingleOrMultipleStringOrUris {
    values: SingleOrMultiple<StringOrUri>,
}

let multiple = SingleOrMultipleStringOrUris {
    values: SingleOrMultiple::Multiple(vec![FromStr::from_str("foo").unwrap(),
                                            FromStr::from_str("https://www.bar.com/").unwrap(),
                                            FromStr::from_str("http://baz/").unwrap()]),
};

let expected_json = r#"{"values":["foo","https://www.bar.com/","http://baz/"]}"#;

let serialized = serde_json::to_string(&multiple).unwrap();
assert_eq!(expected_json, serialized);

let deserialized: SingleOrMultipleStringOrUris = serde_json::from_str(&serialized).unwrap();
assert_eq!(deserialized, multiple);

Variants

A generic string

A parsed URI

Trait Implementations

impl Clone for StringOrUri
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for StringOrUri
[src]

Formats the value using the given formatter.

impl Eq for StringOrUri
[src]

impl PartialEq for StringOrUri
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Hash for StringOrUri
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl AsRef<str> for StringOrUri
[src]

Performs the conversion.

impl FromStr for StringOrUri
[src]

The associated error which can be returned from parsing.

Parses a &str into a StringOrUri. According to RFC 7519, any string containing the ":" character will be treated as a URL. Any invalid URLs will be treated as failure.

impl Serialize for StringOrUri
[src]

Serialize this value into the given Serde serializer. Read more

impl<'de> Deserialize<'de> for StringOrUri
[src]

Deserialize this value from the given Serde deserializer. Read more

impl Display for StringOrUri
[src]

Formats the value using the given formatter. Read more