rhai-url: Working with Urls

rhai-url is an independent Rhai package that enables working with Urls via the url crate.

Documentation

See https://docs.rs/rhai-url for the list of functions.

On crates.io: rhai-url

On GitHub: rhaiscript/rhai-url

Package name: FilesystemPackage

Dependency

Cargo.toml:

[dependencies]
rhai = "1.20.0"
rhai-url = "0.0.1"       # use rhai-url crate

Load Package into Engine

use rhai::Engine;
use rhai::packages::Package;    // needed for 'Package' trait
use rhai_url::UrlPackage;

let mut engine = Engine::new();

// Create new 'UrlPackage' instance
let url = UrlPackage::new();

// Load the package into the `Engine`
url.register_into_engine(&mut engine);

Example

let url = Url("http://example.com/?q=query");

print(url);                 // prints 'http://example.com/?q=query'
print(url.href);            // prints 'http://example.com/?q=query'

print(url.query);           // prints 'q=query'

// fragment and hash are aliases
print(url.fragment);        // prints ''
print(url.hash);            // prints ''

url.query_clear();

print(url.query);           // prints ''

url.query_remove("q");
url.query_append("q", "name");

print(url);                 // prints 'http://example.com/?q=name'