pub struct UrlBuilder { /* private fields */ }Expand description
Fluent URL builder.
Build a URL incrementally by chaining setter methods, then call build
to produce the final String.
Path segments are automatically percent-encoded. Query parameters are form-encoded. No validation of scheme or host is performed — this is a string-composition helper, not a full URL parser.
Implementations§
Source§impl UrlBuilder
impl UrlBuilder
Sourcepub fn scheme(self, scheme: impl Into<String>) -> Self
pub fn scheme(self, scheme: impl Into<String>) -> Self
Set the URL scheme (e.g. "https").
§Examples
use api_bones::url::UrlBuilder;
let url = UrlBuilder::new().scheme("https").host("example.com").build();
assert_eq!(url, "https://example.com");Sourcepub fn port(self, port: u16) -> Self
pub fn port(self, port: u16) -> Self
Set an optional port number.
§Examples
use api_bones::url::UrlBuilder;
let url = UrlBuilder::new()
.scheme("http")
.host("localhost")
.port(8080)
.build();
assert_eq!(url, "http://localhost:8080");Sourcepub fn path(self, segment: impl Into<String>) -> Self
pub fn path(self, segment: impl Into<String>) -> Self
Append a path segment (will be percent-encoded).
Call multiple times to build up /a/b/c style paths.
§Examples
use api_bones::url::UrlBuilder;
let url = UrlBuilder::new()
.scheme("https")
.host("example.com")
.path("v1")
.path("users")
.path("hello world")
.build();
assert_eq!(url, "https://example.com/v1/users/hello%20world");Sourcepub fn query(self, key: impl Into<String>, value: impl ToString) -> Self
pub fn query(self, key: impl Into<String>, value: impl ToString) -> Self
Append a query parameter (key and value are form-encoded).
§Examples
use api_bones::url::UrlBuilder;
let url = UrlBuilder::new()
.scheme("https")
.host("example.com")
.query("q", "hello world")
.build();
assert_eq!(url, "https://example.com?q=hello+world");Sourcepub fn fragment(self, fragment: impl Into<String>) -> Self
pub fn fragment(self, fragment: impl Into<String>) -> Self
Set the URL fragment (the part after #).
§Examples
use api_bones::url::UrlBuilder;
let url = UrlBuilder::new()
.scheme("https")
.host("example.com")
.fragment("section-1")
.build();
assert_eq!(url, "https://example.com#section-1");Sourcepub fn build(&self) -> String
pub fn build(&self) -> String
Produce the final URL string.
§Examples
use api_bones::url::UrlBuilder;
let url = UrlBuilder::new()
.scheme("https")
.host("api.example.com")
.path("v1")
.path("items")
.query("page", 2u32)
.fragment("top")
.build();
assert_eq!(url, "https://api.example.com/v1/items?page=2#top");Trait Implementations§
Source§impl Clone for UrlBuilder
impl Clone for UrlBuilder
Source§fn clone(&self) -> UrlBuilder
fn clone(&self) -> UrlBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UrlBuilder
impl Debug for UrlBuilder
Source§impl Default for UrlBuilder
impl Default for UrlBuilder
Source§fn default() -> UrlBuilder
fn default() -> UrlBuilder
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for UrlBuilder
impl<'de> Deserialize<'de> for UrlBuilder
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 Display for UrlBuilder
impl Display for UrlBuilder
Auto Trait Implementations§
impl Freeze for UrlBuilder
impl RefUnwindSafe for UrlBuilder
impl Send for UrlBuilder
impl Sync for UrlBuilder
impl Unpin for UrlBuilder
impl UnsafeUnpin for UrlBuilder
impl UnwindSafe for UrlBuilder
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ValidateIp for Twhere
T: ToString,
impl<T> ValidateIp for Twhere
T: ToString,
Source§fn validate_ipv4(&self) -> bool
fn validate_ipv4(&self) -> bool
Validates whether the given string is an IP V4
Source§fn validate_ipv6(&self) -> bool
fn validate_ipv6(&self) -> bool
Validates whether the given string is an IP V6
Source§fn validate_ip(&self) -> bool
fn validate_ip(&self) -> bool
Validates whether the given string is an IP