Particular types for different specifications like based on the JSON format, such as JOSE (Javascript Object Signing and Encryption) and JSON-LD (JSON Linked Data).
Add this library to your Cargo.toml
:
[dependencies]
ptypes = "0.1.4"
It is used for properties of a JSON that can be an element of a type or a collection of elements of the same kind—for example, the Type property in the verifiable credentials specification.
use ptypes::OneOrMany;
let one = OneOrMany::One(1);
let many = OneOrMany::Many(vec![1, 2, 3]);
assert_eq!(one.is_one(), true);
assert_eq!(many.is_many(), true);
A Uniform Resource Identifier, as defined by RFC3986.
use ptypes::Uri;
let uri = Uri::try_from("https://example.com".to_string()).unwrap();
assert_eq!(uri, Uri::try_from("https://example.com".to_string()).unwrap());
Used when a property can be either a string or a URI.
use ptypes::StringOrUri;
let string = StringOrUri::String("string".to_string());
let uri = StringOrUri::Uri(Uri::try_from("https://example.com".to_string()).unwrap());
assert_eq!(string.is_string(), true);
assert_eq!(uri.is_uri(), true);
Base64 encoding using the URL- and filename-safe character set defined in Section 5 of RFC 4648.
use ptypes::Base64urlUInt;
let data = Base64urlUInt(vec![1, 2, 3]);
assert_eq!(data, Base64urlUInt::try_from("AQID".to_string()).unwrap());