Available on crate feature
net only.Expand description
URL type for network programming.
This module provides a type-safe abstraction for URLs, ensuring compliance with RFC 3986 URL specifications.
§RFC 3986 URL Rules
According to RFC 3986 §3:
- Total length: up to 2048 characters (common browser limit)
- Scheme: required (e.g., http, https, ftp, file)
- Authority: optional (host:port)
- Path: optional, starts with /
- Query: optional, starts with ?
- Fragment: optional, starts with #
- Scheme must be followed by :
- Authority must be preceded by //
- Scheme names are case-insensitive (stored in lowercase)
- Host and port follow standard network type rules
§Examples
use bare_types::net::Url;
// Create a URL
let url = Url::new("https://example.com")?;
// Get the scheme
assert_eq!(url.scheme(), "https");
// Get the host
assert_eq!(url.host(), Some("example.com"));
// Get the string representation
assert_eq!(url.as_str(), "https://example.com");
// Parse from string
let url: Url = "https://example.com/path?query#fragment".parse()?;Structs§
- Url
- A URL.
Enums§
- UrlError
- Error type for URL validation.