pub struct Url(/* private fields */);Available on crate feature
net only.Expand description
A URL.
This type provides type-safe URLs with RFC 3986 validation.
It uses the newtype pattern with #[repr(transparent)] for zero-cost abstraction.
§Invariants
- Total length is 1-2048 characters
- Scheme is required and case-insensitive (stored in lowercase)
- Authority (host:port) is optional
- Path, query, and fragment are optional
- Scheme must be followed by :
- Authority must be preceded by //
§Examples
use bare_types::net::Url;
// Create a URL
let url = Url::new("https://example.com")?;
// Access the string representation
assert_eq!(url.as_str(), "https://example.com");
// Get the scheme
assert_eq!(url.scheme(), "https");
// Get the host
assert_eq!(url.host(), Some("example.com"));
// Parse from string
let url: Url = "https://example.com/path".parse()?;Implementations§
Source§impl Url
impl Url
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the URL as a string slice.
§Examples
use bare_types::net::Url;
let url = Url::new("https://example.com").unwrap();
assert_eq!(url.as_str(), "https://example.com");Sourcepub const fn as_inner(&self) -> &String<2048>
pub const fn as_inner(&self) -> &String<2048>
Returns a reference to the underlying heapless::String.
§Examples
use bare_types::net::Url;
let url = Url::new("https://example.com").unwrap();
let inner: &heapless::String<2048> = url.as_inner();
assert_eq!(inner.as_str(), "https://example.com");Sourcepub fn into_inner(self) -> String<2048>
pub fn into_inner(self) -> String<2048>
Consumes this URL and returns the underlying string.
§Examples
use bare_types::net::Url;
let url = Url::new("https://example.com").unwrap();
let inner = url.into_inner();
assert_eq!(inner.as_str(), "https://example.com");Sourcepub fn scheme(&self) -> &str
pub fn scheme(&self) -> &str
Returns the scheme of the URL.
§Examples
use bare_types::net::Url;
let url = Url::new("https://example.com").unwrap();
assert_eq!(url.scheme(), "https");Sourcepub fn host(&self) -> Option<&str>
pub fn host(&self) -> Option<&str>
Returns the host of the URL, if present.
§Examples
use bare_types::net::Url;
let url = Url::new("https://example.com").unwrap();
assert_eq!(url.host(), Some("example.com"));Sourcepub fn port(&self) -> Option<&str>
pub fn port(&self) -> Option<&str>
Returns the port of the URL, if present.
§Examples
use bare_types::net::Url;
let url = Url::new("https://example.com:8080").unwrap();
assert_eq!(url.port(), Some("8080"));Sourcepub fn path(&self) -> Option<&str>
pub fn path(&self) -> Option<&str>
Returns the path of the URL, if present.
§Examples
use bare_types::net::Url;
let url = Url::new("https://example.com/path").unwrap();
assert_eq!(url.path(), Some("/path"));Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Url
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for Url
Available on crate feature
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Generate an arbitrary value of
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Generate an arbitrary value of
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Get a size hint for how many bytes out of an
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Get a size hint for how many bytes out of an
Unstructured this type
needs to construct itself. Read moreSource§impl<'de> Deserialize<'de> for Url
impl<'de> Deserialize<'de> for Url
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Url
impl Ord for Url
Source§impl PartialOrd for Url
impl PartialOrd 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<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more