pub struct Url { /* private fields */ }Expand description
A URL that can represent either a web URL or a local file path.
This type provides an ergonomic interface for working with both web URLs (http/https) and local file paths in a unified way.
§Examples
use waterui_url::Url;
// Web URLs
let web_url = Url::parse("https://example.com/image.jpg").unwrap();
assert!(web_url.is_web());
assert_eq!(web_url.scheme(), Some("https"));
// Local file paths
let file_url = Url::from_file_path("/home/user/image.jpg");
assert!(file_url.is_local());
// Automatic detection
let auto_url = Url::new("./relative/path.png");
assert!(auto_url.is_local());Implementations§
Source§impl Url
impl Url
Sourcepub const fn new(url: &'static str) -> Url
pub const fn new(url: &'static str) -> Url
Creates a URL from a static string at compile time.
This function can be evaluated at compile time and automatically detects the URL type (web, local, data, or blob).
For runtime string parsing, use the FromStr trait instead:
url_string.parse::<Url>().
§Panics
Panics if the URL is malformed. This enables compile-time syntax checking: invalid URLs will cause compilation errors when used in const contexts.
// This will fail at compile time - missing host
const INVALID: Url = Url::new("https://");§Examples
use waterui_url::Url;
const WEB_URL: Url = Url::new("https://example.com");
const LOCAL_PATH: Url = Url::new("/absolute/path");
const RELATIVE: Url = Url::new("./relative/path");Sourcepub fn parse(url: impl AsRef<str>) -> Option<Url>
pub fn parse(url: impl AsRef<str>) -> Option<Url>
Parses a URL string, validating it as a proper web URL.
Returns None if the URL is not a valid web URL.
§Examples
use waterui_url::Url;
assert!(Url::parse("https://example.com").is_some());
assert!(Url::parse("http://localhost:3000").is_some());
assert!(Url::parse("/local/path").is_none());Sourcepub fn from_file_path_str(path: impl Into<Str>) -> Url
pub fn from_file_path_str(path: impl Into<Str>) -> Url
Creates a URL from a file path string.
Sourcepub fn from_data(mime_type: &str, data: &[u8]) -> Url
pub fn from_data(mime_type: &str, data: &[u8]) -> Url
Creates a data URL from content and MIME type.
§Examples
use waterui_url::Url;
let url = Url::from_data("image/png", b"...");
assert!(url.is_data());Sourcepub const fn is_absolute(&self) -> bool
pub const fn is_absolute(&self) -> bool
Returns true if this is an absolute path or URL.
Sourcepub const fn is_relative(&self) -> bool
pub const fn is_relative(&self) -> bool
Returns true if this is a relative path.
Sourcepub fn scheme(&self) -> Option<&str>
pub fn scheme(&self) -> Option<&str>
Gets the URL scheme (e.g., “http”, “https”, “file”, “data”).
This is now O(1) - no parsing required!
Sourcepub fn host(&self) -> Option<&str>
pub fn host(&self) -> Option<&str>
Gets the host for web URLs.
This is now O(1) - no parsing required!
Sourcepub fn path(&self) -> &str
pub fn path(&self) -> &str
Gets the path component of the URL.
This is now O(1) - no parsing required!
Sourcepub fn port(&self) -> Option<u16>
pub fn port(&self) -> Option<u16>
Gets the port number for web URLs.
This is a new method enabled by the parsed component structure! Returns the port as a u16, or None if not present.
Sourcepub fn query(&self) -> Option<&str>
pub fn query(&self) -> Option<&str>
Gets the query string (without the ‘?’) for web URLs.
This is a new method enabled by the parsed component structure!
§Examples
use waterui_url::Url;
const URL: Url = Url::new("https://example.com/path?foo=bar&baz=qux");
assert_eq!(URL.query(), Some("foo=bar&baz=qux"));Sourcepub fn fragment(&self) -> Option<&str>
pub fn fragment(&self) -> Option<&str>
Gets the fragment (without the ‘#’) for web URLs.
This is a new method enabled by the parsed component structure!
§Examples
use waterui_url::Url;
const URL: Url = Url::new("https://example.com/path#section");
assert_eq!(URL.fragment(), Some("section"));Gets the authority section (user:pass@host:port) for web URLs.
This is a new method enabled by the parsed component structure!
Sourcepub fn join(&self, path: &str) -> Url
pub fn join(&self, path: &str) -> Url
Joins this URL with a relative path.
§Examples
use waterui_url::Url;
let base = Url::new("https://example.com/images/");
let joined = base.join("photo.jpg");
assert_eq!(joined.as_str(), "https://example.com/images/photo.jpg");Sourcepub fn fetch(&self) -> Fetched
pub fn fetch(&self) -> Fetched
Fetches the content at this URL (for network resources).
This returns a reactive signal that can be watched for changes.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Converts this URL to a string.
Trait Implementations§
Source§impl Ord for Url
impl Ord for Url
Source§impl PartialOrd for Url
impl PartialOrd for Url
Source§impl Signal for Url
impl Signal for Url
impl Eq for Url
impl StructuralPartialEq for Url
Auto Trait Implementations§
impl Freeze for Url
impl RefUnwindSafe for Url
impl !Send for Url
impl !Sync for Url
impl Unpin for Url
impl UnwindSafe for Url
Blanket Implementations§
Source§impl<S> AnimationExt for Swhere
S: SignalExt,
impl<S> AnimationExt for Swhere
S: SignalExt,
Source§fn animated(self) -> WithMetadata<Self, Animation>where
Self: Sized,
fn animated(self) -> WithMetadata<Self, Animation>where
Self: Sized,
Source§fn with_animation(self, animation: Animation) -> WithMetadata<Self, Animation>where
Self: Sized,
fn with_animation(self, animation: Animation) -> WithMetadata<Self, Animation>where
Self: Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> EncodedChars for T
impl<T> EncodedChars for T
Source§fn encoding(&self) -> *mut OnigEncodingTypeST
fn encoding(&self) -> *mut OnigEncodingTypeST
Source§impl<T> IdentifiableExt for T
impl<T> IdentifiableExt for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<C, Output> IntoSignal<Output> for C
impl<C, Output> IntoSignal<Output> for C
Source§impl<C> SignalExt for Cwhere
C: Signal,
impl<C> SignalExt for Cwhere
C: Signal,
Source§fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
Source§fn zip<B: Signal>(self, b: B) -> Zip<Self, B>
fn zip<B: Signal>(self, b: B) -> Zip<Self, B>
Source§fn computed(self) -> Computed<Self::Output>where
Self: Clone + 'static,
fn computed(self) -> Computed<Self::Output>where
Self: Clone + 'static,
Computed wrapper. Read moreSource§fn with<T>(self, metadata: T) -> WithMetadata<Self, T>
fn with<T>(self, metadata: T) -> WithMetadata<Self, T>
Source§impl<C> SignalExt for Cwhere
C: Signal,
impl<C> SignalExt for Cwhere
C: Signal,
Source§fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
Source§fn cached(self) -> Cached<Self>
fn cached(self) -> Cached<Self>
Source§fn computed(self) -> Computed<Self::Output>where
Self: 'static,
fn computed(self) -> Computed<Self::Output>where
Self: 'static,
Computed container.