Url

Struct Url 

Source
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

Source

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");
Source

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());
Source

pub fn from_file_path_str(path: impl Into<Str>) -> Url

Creates a URL from a file path string.

Source

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());
Source

pub const fn is_web(&self) -> bool

Returns true if this is a web URL (http/https/ftp etc).

Source

pub const fn is_local(&self) -> bool

Returns true if this is a local file path.

Source

pub const fn is_data(&self) -> bool

Returns true if this is a data URL.

Source

pub const fn is_blob(&self) -> bool

Returns true if this is a blob URL.

Source

pub const fn is_absolute(&self) -> bool

Returns true if this is an absolute path or URL.

Source

pub fn inner(&self) -> Str

Returns the inner string representation of the URL.

Source

pub const fn is_relative(&self) -> bool

Returns true if this is a relative path.

Source

pub fn scheme(&self) -> Option<&str>

Gets the URL scheme (e.g., “http”, “https”, “file”, “data”).

This is now O(1) - no parsing required!

Source

pub fn host(&self) -> Option<&str>

Gets the host for web URLs.

This is now O(1) - no parsing required!

Source

pub fn path(&self) -> &str

Gets the path component of the URL.

This is now O(1) - no parsing required!

Source

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.

Source

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"));
Source

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"));
Source

pub fn authority(&self) -> Option<&str>

Gets the authority section (user:pass@host:port) for web URLs.

This is a new method enabled by the parsed component structure!

Source

pub fn extension(&self) -> Option<&str>

Gets the file extension if present.

Source

pub fn filename(&self) -> Option<&str>

Gets the filename from the URL path.

Source

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");
Source

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.

Source

pub const fn as_str(&self) -> &str

Returns the underlying string representation.

Source

pub fn into_string(self) -> String

Converts this URL to a string.

Trait Implementations§

Source§

impl AsRef<str> for Url

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Url

Source§

fn clone(&self) -> Url

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Url

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for Url

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<&'static str> for Url

Source§

fn from(value: &'static str) -> Url

Converts to this type from the input type.
Source§

impl<'a> From<Cow<'a, str>> for Url

Source§

fn from(value: Cow<'a, str>) -> Url

Converts to this type from the input type.
Source§

impl From<Str> for Url

Source§

fn from(value: Str) -> Url

Converts to this type from the input type.
Source§

impl From<String> for Url

Source§

fn from(value: String) -> Url

Converts to this type from the input type.
Source§

impl From<Url> for Str

Source§

fn from(url: Url) -> Str

Converts to this type from the input type.
Source§

impl FromStr for Url

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Url, <Url as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Url

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Url

Source§

fn cmp(&self, other: &Url) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Url

Source§

fn eq(&self, other: &Url) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Url

Source§

fn partial_cmp(&self, other: &Url) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Signal for Url

Source§

type Output = Url

The type of value produced by this computation.
Source§

type Guard = ()

The guard type returned by the watch method that manages watcher lifecycle.
Source§

fn get(&self) -> <Url as Signal>::Output

Execute the computation and return the current value.
Source§

fn watch(&self, _watcher: impl Fn(Context<<Url as Signal>::Output>) + 'static)

Register a watcher to be notified when the computed value changes. Read more
Source§

impl Eq for Url

Source§

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 S
where S: SignalExt,

Source§

fn animated(self) -> WithMetadata<Self, Animation>
where Self: Sized,

Apply default animation to this reactive value Read more
Source§

fn with_animation(self, animation: Animation) -> WithMetadata<Self, Animation>
where Self: Sized,

Apply a specific animation to this reactive value Read more
§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> EncodedChars for T
where T: AsRef<str>,

Source§

fn start_ptr(&self) -> *const u8

Pointer to the start of the pattern Read more
Source§

fn limit_ptr(&self) -> *const u8

Pointer to the limit of the pattern buffer Read more
Source§

fn len(&self) -> usize

The length of this buffer
Source§

fn encoding(&self) -> *mut OnigEncodingTypeST

The encoding of the contents of the buffer
Source§

fn is_empty(&self) -> bool

Is the buffer empty?
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> IdentifiableExt for T

Source§

fn use_id<F, Id>(self, f: F) -> UseId<Self, F>
where F: Fn(&Self) -> Id, Id: Ord + Hash,

Wraps the value in a UseId with the provided identification function.
Source§

fn self_id(self) -> SelfId<Self>

Wraps the value in a SelfId, making the value serve as its own identifier.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<C, Output> IntoSignal<Output> for C
where C: Signal, <C as Signal>::Output: 'static + Clone, Output: From<<C as Signal>::Output> + 'static,

Source§

fn into_signal(self) -> <C as IntoSignal<Output>>::Signal

Convert this computation into one that produces the desired output type.

Source§

type Signal = Map<C, fn(<C as Signal>::Output) -> Output, Output>

The specific computation type that will be produced.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<C> SignalExt for C
where C: Signal,

Source§

fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
where F: 'static + Clone + Fn(Self::Output) -> Output, Output: 'static, Self: 'static,

Transforms the output of this computation using the provided function. Read more
Source§

fn zip<B: Signal>(self, b: B) -> Zip<Self, B>
where Self::Output: Clone, B::Output: Clone,

Combines this computation with another computation. Read more
Source§

fn computed(self) -> Computed<Self::Output>
where Self: Clone + 'static,

Converts this computation into a Computed wrapper. Read more
Source§

fn with<T>(self, metadata: T) -> WithMetadata<Self, T>

Attaches metadata to this computation. Read more
Source§

fn animated(self) -> impl Signal<Output = Self::Output>

Marks this computation for animation with default settings. Read more
Source§

impl<C> SignalExt for C
where C: Signal,

Source§

fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
where F: 'static + Clone + Fn(Self::Output) -> Output, Output: 'static, Self: 'static,

Transforms the output of this signal using the provided function.
Source§

fn zip<B>(self, b: B) -> Zip<Self, B>
where B: Signal, Self::Output: Clone, <B as Signal>::Output: Clone,

Combines this signal with another signal into a tuple.
Source§

fn cached(self) -> Cached<Self>
where Self::Output: Clone,

Wraps this signal with caching to avoid redundant computations.
Source§

fn computed(self) -> Computed<Self::Output>
where Self: 'static,

Converts this signal into a type-erased Computed container.
Source§

fn with<T>(self, metadata: T) -> WithMetadata<Self, T>

Attaches metadata to this signal’s watcher notifications.
Source§

fn debounce(self, duration: Duration) -> Debounce<Self, DefaultExecutor>
where Self::Output: Clone,

Creates a debounced version of this signal. Read more
Source§

fn throttle(self, duration: Duration) -> Throttle<Self, DefaultExecutor>
where Self::Output: Clone,

Creates a throttled version of this signal. Read more
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more