pub struct HttpUrlBuilder { /* private fields */ }Expand description
Builder for constructing HttpUrl values programmatically.
§Example
use http_url::{HttpUrl, Scheme};
let url = HttpUrl::builder()
.scheme(Scheme::Https)
.host("example.com")
.add_path_segment("api")
.add_path_segment("v1")
.add_query_parameter("key", "value")
.fragment("section")
.build()
.unwrap();
assert_eq!(url.to_string(), "https://example.com/api/v1?key=value#section");Implementations§
Source§impl HttpUrlBuilder
impl HttpUrlBuilder
Sourcepub fn add_path_segment(self, segment: &str) -> Self
pub fn add_path_segment(self, segment: &str) -> Self
Add a path segment (decoded form, will be percent-encoded on build).
Sourcepub fn add_path_segments(self, segments: &[&str]) -> Self
pub fn add_path_segments(self, segments: &[&str]) -> Self
Add multiple path segments.
Sourcepub fn set_path(self, path: &str) -> Self
pub fn set_path(self, path: &str) -> Self
Set the entire path from a decoded path string (e.g., /a/b/c).
The path is split on / and each segment is decoded.
Sourcepub fn set_encoded_path(self, path: &str) -> Self
pub fn set_encoded_path(self, path: &str) -> Self
Set the entire path from an already-encoded path string. Each segment is percent-decoded before storage.
Sourcepub fn add_query_parameter(self, name: &str, value: &str) -> Self
pub fn add_query_parameter(self, name: &str, value: &str) -> Self
Add a query parameter (name and value in decoded form).
Sourcepub fn remove_query_parameter(self, name: &str) -> Self
pub fn remove_query_parameter(self, name: &str) -> Self
Remove all query parameters with the given name.
Sourcepub fn clear_query_parameters(self) -> Self
pub fn clear_query_parameters(self) -> Self
Clear all query parameters.
Sourcepub fn add_encoded_query_parameter(self, name: &str, value: &str) -> Self
pub fn add_encoded_query_parameter(self, name: &str, value: &str) -> Self
Add a query parameter from already-encoded name and value.
Sourcepub fn encoded_fragment(self, fragment: &str) -> Self
pub fn encoded_fragment(self, fragment: &str) -> Self
Set the fragment from an encoded form.
Sourcepub fn remove_fragment(self) -> Self
pub fn remove_fragment(self) -> Self
Remove the fragment.
Trait Implementations§
Source§impl Clone for HttpUrlBuilder
impl Clone for HttpUrlBuilder
Source§fn clone(&self) -> HttpUrlBuilder
fn clone(&self) -> HttpUrlBuilder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 HttpUrlBuilder
impl Debug for HttpUrlBuilder
Auto Trait Implementations§
impl Freeze for HttpUrlBuilder
impl RefUnwindSafe for HttpUrlBuilder
impl Send for HttpUrlBuilder
impl Sync for HttpUrlBuilder
impl Unpin for HttpUrlBuilder
impl UnsafeUnpin for HttpUrlBuilder
impl UnwindSafe for HttpUrlBuilder
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