Skip to content

Latest commit

 

History

History
69 lines (45 loc) · 2.07 KB

README.md

File metadata and controls

69 lines (45 loc) · 2.07 KB

ptypes

Rust License Build & Test Coverage Status

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).

Usage

Add this library to your Cargo.toml:

[dependencies]
ptypes = "0.1.4"

Examples

OneOrMany

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);

Uri

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());

StringOrUri

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);

Base64urlUInt

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());