rfc6570-level-2

Crates.iorfc6570-level-2
lib.rsrfc6570-level-2
version1.2.0
sourcesrc
created_at2021-01-23 14:30:21.777827
updated_at2021-01-24 09:20:45.478685
descriptionA library for validating and processing strings as RFC6570-compliant URIs (up to level 2)
homepage
repositoryhttps://gitlab.com/Kage-Yami/rfc6570-level-2-rust
max_upload_size
id345658
size66,647
Joel S (Kage-Yami)

documentation

README

RFC6570 Level 2 - Rust

Overview

A Rust library for validating and processing strings as RFC6570-compliant URIs (up to level 2).

docs.io documentation crates.io version crates.io downloads Gitlab pipeline status Gitlab code coverage Lines of code Dependents License

Versioning

This project follows Semantic Versioning principals starting with v1.0.0

Repository information

This repository is located on GitLab.com.

Usage

To use this library, instantiate an UriTemplate with a relevant string. From here, the result can be "discarded" if only validation of the input string is needed, or a list of contained expressions or variables can be retrieved with expressions() or variables(). Finally, the URI template can be expanded by called expand() with a HashMap<&str, &str> of variables and values.

use rfc6570_level_2::UriTemplate;

let template = UriTemplate::new("https://example.com/{resource}/{+id}{#field}")?;

// What variables are available?
let variables: Vec<&str> = template.variables().collect();
assert_eq!(variables, vec!["resource", "id", "field"]);

let var_map = [
    ("resource", "user"),
    ("id", "5"),
    ("field", "email"),
].iter().cloned().collect();

// Expand the template
let uri = template.expand(&var_map);
assert_eq!(uri, "https://example.com/user/5#email");
Commit count: 49

cargo fmt