Skip to main content

Crate use_url

Crate use_url 

Source
Expand description

§use-url

Small URL utility primitives for RustUse.

§Experimental

use-url is experimental while the use-web workspace remains below 0.3.0. Expect small API adjustments during the first release wave.

§Example

use use_url::{extract_host, parse_url_basic, remove_query};

let parts = parse_url_basic("https://example.com/docs?page=2#intro").unwrap();

assert_eq!(parts.scheme, "https");
assert_eq!(extract_host("https://example.com/docs?page=2#intro").as_deref(), Some("example.com"));
assert_eq!(remove_query("https://example.com/docs?page=2#intro"), "https://example.com/docs#intro");

§Scope

  • Basic URL splitting for scheme, host, port, path, query, and fragment.
  • Lightweight path and suffix helpers.
  • Graceful handling for malformed or partial input.

§Non-goals

  • Full WHATWG URL parsing.
  • DNS validation.
  • HTTP client behavior.
  • IDNA handling.

§License

Licensed under either of the following, at your option:

  • Apache License, Version 2.0
  • MIT license

Structs§

UrlParts
Lightweight URL parts extracted with simple string splitting.

Functions§

ensure_trailing_slash
Ensures that the URL or path ends with a trailing slash before any query or fragment.
extract_host
Extracts the URL host when available.
extract_path
Extracts the URL path when available.
extract_port
Extracts the URL port when available.
is_http_url
Returns true when the input is an HTTP URL.
is_https_url
Returns true when the input is an HTTPS URL.
looks_like_url
Returns true when the input looks like a parsable absolute URL.
parse_url_basic
Parses a URL with lightweight string splitting.
remove_fragment
Removes the fragment portion from a URL.
remove_query
Removes the query portion and preserves any fragment.
strip_trailing_slash
Removes trailing slashes before any query or fragment.