Enum biscuit::StringOrUri

source ·
pub enum StringOrUri {
    String(String),
    Uri(Url),
}
Expand description

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;
#[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

String(String)

A generic string

Uri(Url)

A parsed URI

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Formats the value using the given formatter. Read more

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.

The associated error which can be returned from parsing.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.