uri-template-core 0.1.0

RFC6570 URI Template library for Rust, with parsing, expansion, compile-time checked macros, and no_std support.
Documentation
use crate::UriTemplate;

#[test]
pub fn debug() {
    // ############################# Level 1
    print_ok("");
    print_ok("{var}");
    print_ok("'{var}'");

    // ############################# Level 2
    print_ok("{+var}");
    print_ok("{+path}/here");

    // ############################# Level 3
    print_ok("map?{x,hello,y}");
    print_ok("map?{+x,hello,y}");
    print_ok("map?{#x,hello,y}/here");
    print_ok("?fixed=yes{.x,y}/here");
    print_ok("?fixed=yes{.a*}/here");

    // ############################# Level 4
    print_ok("你好%25fixed=yes{.var1:30,var2,var3}/here");
    print_ok("%2F%25fixed=yes{+var1:3000,var2*,var3}/here");
    print_ok("%2F%25fixed=yes{+var1*}/here");
    print_ok("%FF%25fixed=yes{+var1*}/here");

    // #############################
    print_ok("https://example.com/api/users/{user_id}{/action}{?query}");

    // ############################# corner cases
    print_ok("%7Bvar%7D");
    print_ok("%7B{var}");
    print_ok("你好{var}");
}

fn print_ok(s: &'static str) {
    let template = UriTemplate::new(s);
    assert!(
        template.is_ok(),
        "expected Ok but got error {}",
        template.unwrap_err()
    );
    let template = template.unwrap();
    let template_vars = template.variables();
    let template_literals = template.literals();
    println!("{template:#?}\nVariables: {template_vars:?}\nLiterals: {template_literals:?}\n");
    println!("--------------------------------------------------------------------------------\n")
}