pub struct Url { /* private fields */ }
Expand description
A parsed URL record.
Implementations
sourceimpl Url
impl Url
sourcepub fn parse(input: &str) -> Result<Url, ParseError>
pub fn parse(input: &str) -> Result<Url, ParseError>
Parse an absolute URL from a string.
Examples
use url::Url;
let url = Url::parse("https://example.net")?;
Errors
If the function can not parse an absolute URL from the given string,
a ParseError
variant will be returned.
sourcepub fn parse_with_params<I, K, V>(
input: &str,
iter: I
) -> Result<Url, ParseError> where
I: IntoIterator,
K: AsRef<str>,
V: AsRef<str>,
<I as IntoIterator>::Item: Borrow<(K, V)>,
pub fn parse_with_params<I, K, V>(
input: &str,
iter: I
) -> Result<Url, ParseError> where
I: IntoIterator,
K: AsRef<str>,
V: AsRef<str>,
<I as IntoIterator>::Item: Borrow<(K, V)>,
Parse an absolute URL from a string and add params to its query string.
Existing params are not removed.
Examples
use url::Url;
let url = Url::parse_with_params("https://example.net?dont=clobberme",
&[("lang", "rust"), ("browser", "servo")])?;
assert_eq!("https://example.net/?dont=clobberme&lang=rust&browser=servo", url.as_str());
Errors
If the function can not parse an absolute URL from the given string,
a ParseError
variant will be returned.
sourcepub fn join(&self, input: &str) -> Result<Url, ParseError>
pub fn join(&self, input: &str) -> Result<Url, ParseError>
Parse a string as an URL, with this URL as the base URL.
The inverse of this is make_relative
.
Note: a trailing slash is significant. Without it, the last path component is considered to be a “file” name to be removed to get at the “directory” that is used as the base:
Examples
use url::Url;
let base = Url::parse("https://example.net/a/b.html")?;
let url = base.join("c.png")?;
assert_eq!(url.as_str(), "https://example.net/a/c.png"); // Not /a/b.html/c.png
let base = Url::parse("https://example.net/a/b/")?;
let url = base.join("c.png")?;
assert_eq!(url.as_str(), "https://example.net/a/b/c.png");
Errors
If the function can not parse an URL from the given string
with this URL as the base URL, a ParseError
variant will be returned.
sourcepub fn make_relative(&self, url: &Url) -> Option<String>
pub fn make_relative(&self, url: &Url) -> Option<String>
Creates a relative URL if possible, with this URL as the base URL.
This is the inverse of join
.
Examples
use url::Url;
let base = Url::parse("https://example.net/a/b.html")?;
let url = Url::parse("https://example.net/a/c.png")?;
let relative = base.make_relative(&url);
assert_eq!(relative.as_ref().map(|s| s.as_str()), Some("c.png"));
let base = Url::parse("https://example.net/a/b/")?;
let url = Url::parse("https://example.net/a/b/c.png")?;
let relative = base.make_relative(&url);
assert_eq!(relative.as_ref().map(|s| s.as_str()), Some("c.png"));
let base = Url::parse("https://example.net/a/b/")?;
let url = Url::parse("https://example.net/a/d/c.png")?;
let relative = base.make_relative(&url);
assert_eq!(relative.as_ref().map(|s| s.as_str()), Some("../d/c.png"));
let base = Url::parse("https://example.net/a/b.html?c=d")?;
let url = Url::parse("https://example.net/a/b.html?e=f")?;
let relative = base.make_relative(&url);
assert_eq!(relative.as_ref().map(|s| s.as_str()), Some("?e=f"));
Errors
If this URL can’t be a base for the given URL, None
is returned.
This is for example the case if the scheme, host or port are not the same.
sourcepub fn options<'a>() -> ParseOptions<'a>
pub fn options<'a>() -> ParseOptions<'a>
Return a default ParseOptions
that can fully configure the URL parser.
Examples
Get default ParseOptions
, then change base url
use url::Url;
let options = Url::options();
let api = Url::parse("https://api.example.com")?;
let base_url = options.base_url(Some(&api));
let version_url = base_url.parse("version.json")?;
assert_eq!(version_url.as_str(), "https://api.example.com/version.json");
sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Return the serialization of this URL.
This is fast since that serialization is already stored in the Url
struct.
Examples
use url::Url;
let url_str = "https://example.net/";
let url = Url::parse(url_str)?;
assert_eq!(url.as_str(), url_str);
sourcepub fn into_string(self) -> String
👎 Deprecated since 2.3.0: use Into<String>
pub fn into_string(self) -> String
use Into<String>
Return the serialization of this URL.
This consumes the Url
and takes ownership of the String
stored in it.
Examples
use url::Url;
let url_str = "https://example.net/";
let url = Url::parse(url_str)?;
assert_eq!(String::from(url), url_str);
sourcepub fn origin(&self) -> Origin
pub fn origin(&self) -> Origin
Return the origin of this URL (https://url.spec.whatwg.org/#origin)
Note: this returns an opaque origin for file:
URLs, which causes
url.origin() != url.origin()
.
Examples
URL with ftp
scheme:
use url::{Host, Origin, Url};
let url = Url::parse("ftp://example.com/foo")?;
assert_eq!(url.origin(),
Origin::Tuple("ftp".into(),
Host::Domain("example.com".into()),
21));
URL with blob
scheme:
use url::{Host, Origin, Url};
let url = Url::parse("blob:https://example.com/foo")?;
assert_eq!(url.origin(),
Origin::Tuple("https".into(),
Host::Domain("example.com".into()),
443));
URL with file
scheme:
use url::{Host, Origin, Url};
let url = Url::parse("file:///tmp/foo")?;
assert!(!url.origin().is_tuple());
let other_url = Url::parse("file:///tmp/foo")?;
assert!(url.origin() != other_url.origin());
URL with other scheme:
use url::{Host, Origin, Url};
let url = Url::parse("foo:bar")?;
assert!(!url.origin().is_tuple());
sourcepub fn scheme(&self) -> &str
pub fn scheme(&self) -> &str
Return the scheme of this URL, lower-cased, as an ASCII string without the ‘:’ delimiter.
Examples
use url::Url;
let url = Url::parse("file:///tmp/foo")?;
assert_eq!(url.scheme(), "file");
Return whether the URL has an ‘authority’, which can contain a username, password, host, and port number.
URLs that do not are either path-only like unix:/run/foo.socket
or cannot-be-a-base like data:text/plain,Stuff
.
Examples
use url::Url;
let url = Url::parse("ftp://rms@example.com")?;
assert!(url.has_authority());
let url = Url::parse("unix:/run/foo.socket")?;
assert!(!url.has_authority());
let url = Url::parse("data:text/plain,Stuff")?;
assert!(!url.has_authority());
sourcepub fn cannot_be_a_base(&self) -> bool
pub fn cannot_be_a_base(&self) -> bool
Return whether this URL is a cannot-be-a-base URL, meaning that parsing a relative URL string with this URL as the base will return an error.
This is the case if the scheme and :
delimiter are not followed by a /
slash,
as is typically the case of data:
and mailto:
URLs.
Examples
use url::Url;
let url = Url::parse("ftp://rms@example.com")?;
assert!(!url.cannot_be_a_base());
let url = Url::parse("unix:/run/foo.socket")?;
assert!(!url.cannot_be_a_base());
let url = Url::parse("data:text/plain,Stuff")?;
assert!(url.cannot_be_a_base());
sourcepub fn username(&self) -> &str
pub fn username(&self) -> &str
Return the username for this URL (typically the empty string) as a percent-encoded ASCII string.
Examples
use url::Url;
let url = Url::parse("ftp://rms@example.com")?;
assert_eq!(url.username(), "rms");
let url = Url::parse("ftp://:secret123@example.com")?;
assert_eq!(url.username(), "");
let url = Url::parse("https://example.com")?;
assert_eq!(url.username(), "");
sourcepub fn password(&self) -> Option<&str>
pub fn password(&self) -> Option<&str>
Return the password for this URL, if any, as a percent-encoded ASCII string.
Examples
use url::Url;
let url = Url::parse("ftp://rms:secret123@example.com")?;
assert_eq!(url.password(), Some("secret123"));
let url = Url::parse("ftp://:secret123@example.com")?;
assert_eq!(url.password(), Some("secret123"));
let url = Url::parse("ftp://rms@example.com")?;
assert_eq!(url.password(), None);
let url = Url::parse("https://example.com")?;
assert_eq!(url.password(), None);
sourcepub fn has_host(&self) -> bool
pub fn has_host(&self) -> bool
Equivalent to url.host().is_some()
.
Examples
use url::Url;
let url = Url::parse("ftp://rms@example.com")?;
assert!(url.has_host());
let url = Url::parse("unix:/run/foo.socket")?;
assert!(!url.has_host());
let url = Url::parse("data:text/plain,Stuff")?;
assert!(!url.has_host());
sourcepub fn host_str(&self) -> Option<&str>
pub fn host_str(&self) -> Option<&str>
Return the string representation of the host (domain or IP address) for this URL, if any.
Non-ASCII domains are punycode-encoded per IDNA if this is the host
of a special URL, or percent encoded for non-special URLs.
IPv6 addresses are given between [
and ]
brackets.
Cannot-be-a-base URLs (typical of data:
and mailto:
) and some file:
URLs
don’t have a host.
See also the host
method.
Examples
use url::Url;
let url = Url::parse("https://127.0.0.1/index.html")?;
assert_eq!(url.host_str(), Some("127.0.0.1"));
let url = Url::parse("ftp://rms@example.com")?;
assert_eq!(url.host_str(), Some("example.com"));
let url = Url::parse("unix:/run/foo.socket")?;
assert_eq!(url.host_str(), None);
let url = Url::parse("data:text/plain,Stuff")?;
assert_eq!(url.host_str(), None);
sourcepub fn host(&self) -> Option<Host<&str>>
pub fn host(&self) -> Option<Host<&str>>
Return the parsed representation of the host for this URL. Non-ASCII domain labels are punycode-encoded per IDNA if this is the host of a special URL, or percent encoded for non-special URLs.
Cannot-be-a-base URLs (typical of data:
and mailto:
) and some file:
URLs
don’t have a host.
See also the host_str
method.
Examples
use url::Url;
let url = Url::parse("https://127.0.0.1/index.html")?;
assert!(url.host().is_some());
let url = Url::parse("ftp://rms@example.com")?;
assert!(url.host().is_some());
let url = Url::parse("unix:/run/foo.socket")?;
assert!(url.host().is_none());
let url = Url::parse("data:text/plain,Stuff")?;
assert!(url.host().is_none());
sourcepub fn domain(&self) -> Option<&str>
pub fn domain(&self) -> Option<&str>
If this URL has a host and it is a domain name (not an IP address), return it. Non-ASCII domains are punycode-encoded per IDNA if this is the host of a special URL, or percent encoded for non-special URLs.
Examples
use url::Url;
let url = Url::parse("https://127.0.0.1/")?;
assert_eq!(url.domain(), None);
let url = Url::parse("mailto:rms@example.net")?;
assert_eq!(url.domain(), None);
let url = Url::parse("https://example.com/")?;
assert_eq!(url.domain(), Some("example.com"));
sourcepub fn port(&self) -> Option<u16>
pub fn port(&self) -> Option<u16>
Return the port number for this URL, if any.
Note that default port numbers are never reflected by the serialization,
use the port_or_known_default()
method if you want a default port number returned.
Examples
use url::Url;
let url = Url::parse("https://example.com")?;
assert_eq!(url.port(), None);
let url = Url::parse("https://example.com:443/")?;
assert_eq!(url.port(), None);
let url = Url::parse("ssh://example.com:22")?;
assert_eq!(url.port(), Some(22));
sourcepub fn port_or_known_default(&self) -> Option<u16>
pub fn port_or_known_default(&self) -> Option<u16>
Return the port number for this URL, or the default port number if it is known.
This method only knows the default port number
of the http
, https
, ws
, wss
and ftp
schemes.
For URLs in these schemes, this method always returns Some(_)
.
For other schemes, it is the same as Url::port()
.
Examples
use url::Url;
let url = Url::parse("foo://example.com")?;
assert_eq!(url.port_or_known_default(), None);
let url = Url::parse("foo://example.com:1456")?;
assert_eq!(url.port_or_known_default(), Some(1456));
let url = Url::parse("https://example.com")?;
assert_eq!(url.port_or_known_default(), Some(443));
sourcepub fn socket_addrs(
&self,
default_port_number: impl Fn() -> Option<u16>
) -> Result<Vec<SocketAddr, Global>, Error>
pub fn socket_addrs(
&self,
default_port_number: impl Fn() -> Option<u16>
) -> Result<Vec<SocketAddr, Global>, Error>
Resolve a URL’s host and port number to SocketAddr
.
If the URL has the default port number of a scheme that is unknown to this library,
default_port_number
provides an opportunity to provide the actual port number.
In non-example code this should be implemented either simply as || None
,
or by matching on the URL’s .scheme()
.
If the host is a domain, it is resolved using the standard library’s DNS support.
Examples
let url = url::Url::parse("https://example.net/").unwrap();
let addrs = url.socket_addrs(|| None).unwrap();
std::net::TcpStream::connect(&*addrs)
/// With application-specific known default port numbers
fn socket_addrs(url: url::Url) -> std::io::Result<Vec<std::net::SocketAddr>> {
url.socket_addrs(|| match url.scheme() {
"socks5" | "socks5h" => Some(1080),
_ => None,
})
}
sourcepub fn path(&self) -> &str
pub fn path(&self) -> &str
Return the path for this URL, as a percent-encoded ASCII string. For cannot-be-a-base URLs, this is an arbitrary string that doesn’t start with ‘/’. For other URLs, this starts with a ‘/’ slash and continues with slash-separated path segments.
Examples
use url::{Url, ParseError};
let url = Url::parse("https://example.com/api/versions?page=2")?;
assert_eq!(url.path(), "/api/versions");
let url = Url::parse("https://example.com")?;
assert_eq!(url.path(), "/");
let url = Url::parse("https://example.com/countries/việt nam")?;
assert_eq!(url.path(), "/countries/vi%E1%BB%87t%20nam");
sourcepub fn path_segments(&self) -> Option<Split<'_, char>>
pub fn path_segments(&self) -> Option<Split<'_, char>>
Unless this URL is cannot-be-a-base, return an iterator of ‘/’ slash-separated path segments, each as a percent-encoded ASCII string.
Return None
for cannot-be-a-base URLs.
When Some
is returned, the iterator always contains at least one string
(which may be empty).
Examples
use url::Url;
let url = Url::parse("https://example.com/foo/bar")?;
let mut path_segments = url.path_segments().ok_or_else(|| "cannot be base")?;
assert_eq!(path_segments.next(), Some("foo"));
assert_eq!(path_segments.next(), Some("bar"));
assert_eq!(path_segments.next(), None);
let url = Url::parse("https://example.com")?;
let mut path_segments = url.path_segments().ok_or_else(|| "cannot be base")?;
assert_eq!(path_segments.next(), Some(""));
assert_eq!(path_segments.next(), None);
let url = Url::parse("data:text/plain,HelloWorld")?;
assert!(url.path_segments().is_none());
let url = Url::parse("https://example.com/countries/việt nam")?;
let mut path_segments = url.path_segments().ok_or_else(|| "cannot be base")?;
assert_eq!(path_segments.next(), Some("countries"));
assert_eq!(path_segments.next(), Some("vi%E1%BB%87t%20nam"));
sourcepub fn query(&self) -> Option<&str>
pub fn query(&self) -> Option<&str>
Return this URL’s query string, if any, as a percent-encoded ASCII string.
Examples
use url::Url;
fn run() -> Result<(), ParseError> {
let url = Url::parse("https://example.com/products?page=2")?;
let query = url.query();
assert_eq!(query, Some("page=2"));
let url = Url::parse("https://example.com/products")?;
let query = url.query();
assert!(query.is_none());
let url = Url::parse("https://example.com/?country=español")?;
let query = url.query();
assert_eq!(query, Some("country=espa%C3%B1ol"));
sourcepub fn query_pairs(&self) -> Parse<'_>
pub fn query_pairs(&self) -> Parse<'_>
Parse the URL’s query string, if any, as application/x-www-form-urlencoded
and return an iterator of (key, value) pairs.
Examples
use std::borrow::Cow;
use url::Url;
let url = Url::parse("https://example.com/products?page=2&sort=desc")?;
let mut pairs = url.query_pairs();
assert_eq!(pairs.count(), 2);
assert_eq!(pairs.next(), Some((Cow::Borrowed("page"), Cow::Borrowed("2"))));
assert_eq!(pairs.next(), Some((Cow::Borrowed("sort"), Cow::Borrowed("desc"))));
sourcepub fn fragment(&self) -> Option<&str>
pub fn fragment(&self) -> Option<&str>
Return this URL’s fragment identifier, if any.
A fragment is the part of the URL after the #
symbol.
The fragment is optional and, if present, contains a fragment identifier
that identifies a secondary resource, such as a section heading
of a document.
In HTML, the fragment identifier is usually the id attribute of a an element that is scrolled to on load. Browsers typically will not send the fragment portion of a URL to the server.
Note: the parser did not percent-encode this component, but the input may have been percent-encoded already.
Examples
use url::Url;
let url = Url::parse("https://example.com/data.csv#row=4")?;
assert_eq!(url.fragment(), Some("row=4"));
let url = Url::parse("https://example.com/data.csv#cell=4,1-6,2")?;
assert_eq!(url.fragment(), Some("cell=4,1-6,2"));
sourcepub fn set_fragment(&mut self, fragment: Option<&str>)
pub fn set_fragment(&mut self, fragment: Option<&str>)
Change this URL’s fragment identifier.
Examples
use url::Url;
let mut url = Url::parse("https://example.com/data.csv")?;
assert_eq!(url.as_str(), "https://example.com/data.csv");
url.set_fragment(Some("cell=4,1-6,2"));
assert_eq!(url.as_str(), "https://example.com/data.csv#cell=4,1-6,2");
assert_eq!(url.fragment(), Some("cell=4,1-6,2"));
url.set_fragment(None);
assert_eq!(url.as_str(), "https://example.com/data.csv");
assert!(url.fragment().is_none());
sourcepub fn set_query(&mut self, query: Option<&str>)
pub fn set_query(&mut self, query: Option<&str>)
Change this URL’s query string.
Examples
use url::Url;
let mut url = Url::parse("https://example.com/products")?;
assert_eq!(url.as_str(), "https://example.com/products");
url.set_query(Some("page=2"));
assert_eq!(url.as_str(), "https://example.com/products?page=2");
assert_eq!(url.query(), Some("page=2"));
sourcepub fn query_pairs_mut(&mut self) -> Serializer<'_, UrlQuery<'_>>
pub fn query_pairs_mut(&mut self) -> Serializer<'_, UrlQuery<'_>>
Manipulate this URL’s query string, viewed as a sequence of name/value pairs
in application/x-www-form-urlencoded
syntax.
The return value has a method-chaining API:
let mut url = Url::parse("https://example.net?lang=fr#nav")?;
assert_eq!(url.query(), Some("lang=fr"));
url.query_pairs_mut().append_pair("foo", "bar");
assert_eq!(url.query(), Some("lang=fr&foo=bar"));
assert_eq!(url.as_str(), "https://example.net/?lang=fr&foo=bar#nav");
url.query_pairs_mut()
.clear()
.append_pair("foo", "bar & baz")
.append_pair("saisons", "\u{00C9}t\u{00E9}+hiver");
assert_eq!(url.query(), Some("foo=bar+%26+baz&saisons=%C3%89t%C3%A9%2Bhiver"));
assert_eq!(url.as_str(),
"https://example.net/?foo=bar+%26+baz&saisons=%C3%89t%C3%A9%2Bhiver#nav");
Note: url.query_pairs_mut().clear();
is equivalent to url.set_query(Some(""))
,
not url.set_query(None)
.
The state of Url
is unspecified if this return value is leaked without being dropped.
sourcepub fn set_path(&mut self, path: &str)
pub fn set_path(&mut self, path: &str)
Change this URL’s path.
Examples
use url::Url;
let mut url = Url::parse("https://example.com")?;
url.set_path("api/comments");
assert_eq!(url.as_str(), "https://example.com/api/comments");
assert_eq!(url.path(), "/api/comments");
let mut url = Url::parse("https://example.com/api")?;
url.set_path("data/report.csv");
assert_eq!(url.as_str(), "https://example.com/data/report.csv");
assert_eq!(url.path(), "/data/report.csv");
sourcepub fn path_segments_mut(&mut self) -> Result<PathSegmentsMut<'_>, ()>
pub fn path_segments_mut(&mut self) -> Result<PathSegmentsMut<'_>, ()>
Return an object with methods to manipulate this URL’s path segments.
Return Err(())
if this URL is cannot-be-a-base.
sourcepub fn set_port(&mut self, port: Option<u16>) -> Result<(), ()>
pub fn set_port(&mut self, port: Option<u16>) -> Result<(), ()>
Change this URL’s port number.
Note that default port numbers are not reflected in the serialization.
If this URL is cannot-be-a-base, does not have a host, or has the file
scheme;
do nothing and return Err
.
Examples
use url::Url;
let mut url = Url::parse("ssh://example.net:2048/")?;
url.set_port(Some(4096)).map_err(|_| "cannot be base")?;
assert_eq!(url.as_str(), "ssh://example.net:4096/");
url.set_port(None).map_err(|_| "cannot be base")?;
assert_eq!(url.as_str(), "ssh://example.net/");
Known default port numbers are not reflected:
use url::Url;
let mut url = Url::parse("https://example.org/")?;
url.set_port(Some(443)).map_err(|_| "cannot be base")?;
assert!(url.port().is_none());
Cannot set port for cannot-be-a-base URLs:
use url::Url;
let mut url = Url::parse("mailto:rms@example.net")?;
let result = url.set_port(Some(80));
assert!(result.is_err());
let result = url.set_port(None);
assert!(result.is_err());
sourcepub fn set_host(&mut self, host: Option<&str>) -> Result<(), ParseError>
pub fn set_host(&mut self, host: Option<&str>) -> Result<(), ParseError>
Change this URL’s host.
Removing the host (calling this with None
)
will also remove any username, password, and port number.
Examples
Change host:
use url::Url;
let mut url = Url::parse("https://example.net")?;
let result = url.set_host(Some("rust-lang.org"));
assert!(result.is_ok());
assert_eq!(url.as_str(), "https://rust-lang.org/");
Remove host:
use url::Url;
let mut url = Url::parse("foo://example.net")?;
let result = url.set_host(None);
assert!(result.is_ok());
assert_eq!(url.as_str(), "foo:/");
Cannot remove host for ‘special’ schemes (e.g. http
):
use url::Url;
let mut url = Url::parse("https://example.net")?;
let result = url.set_host(None);
assert!(result.is_err());
assert_eq!(url.as_str(), "https://example.net/");
Cannot change or remove host for cannot-be-a-base URLs:
use url::Url;
let mut url = Url::parse("mailto:rms@example.net")?;
let result = url.set_host(Some("rust-lang.org"));
assert!(result.is_err());
assert_eq!(url.as_str(), "mailto:rms@example.net");
let result = url.set_host(None);
assert!(result.is_err());
assert_eq!(url.as_str(), "mailto:rms@example.net");
Errors
If this URL is cannot-be-a-base or there is an error parsing the given host
,
a ParseError
variant will be returned.
sourcepub fn set_ip_host(&mut self, address: IpAddr) -> Result<(), ()>
pub fn set_ip_host(&mut self, address: IpAddr) -> Result<(), ()>
Change this URL’s host to the given IP address.
If this URL is cannot-be-a-base, do nothing and return Err
.
Compared to Url::set_host
, this skips the host parser.
Examples
use url::{Url, ParseError};
let mut url = Url::parse("http://example.com")?;
url.set_ip_host("127.0.0.1".parse().unwrap());
assert_eq!(url.host_str(), Some("127.0.0.1"));
assert_eq!(url.as_str(), "http://127.0.0.1/");
Cannot change URL’s from mailto(cannot-be-base) to ip:
use url::{Url, ParseError};
let mut url = Url::parse("mailto:rms@example.com")?;
let result = url.set_ip_host("127.0.0.1".parse().unwrap());
assert_eq!(url.as_str(), "mailto:rms@example.com");
assert!(result.is_err());
sourcepub fn set_password(&mut self, password: Option<&str>) -> Result<(), ()>
pub fn set_password(&mut self, password: Option<&str>) -> Result<(), ()>
Change this URL’s password.
If this URL is cannot-be-a-base or does not have a host, do nothing and return Err
.
Examples
use url::{Url, ParseError};
let mut url = Url::parse("mailto:rmz@example.com")?;
let result = url.set_password(Some("secret_password"));
assert!(result.is_err());
let mut url = Url::parse("ftp://user1:secret1@example.com")?;
let result = url.set_password(Some("secret_password"));
assert_eq!(url.password(), Some("secret_password"));
let mut url = Url::parse("ftp://user2:@example.com")?;
let result = url.set_password(Some("secret2"));
assert!(result.is_ok());
assert_eq!(url.password(), Some("secret2"));
sourcepub fn set_username(&mut self, username: &str) -> Result<(), ()>
pub fn set_username(&mut self, username: &str) -> Result<(), ()>
Change this URL’s username.
If this URL is cannot-be-a-base or does not have a host, do nothing and return Err
.
Examples
Cannot setup username from mailto(cannot-be-base)
use url::{Url, ParseError};
let mut url = Url::parse("mailto:rmz@example.com")?;
let result = url.set_username("user1");
assert_eq!(url.as_str(), "mailto:rmz@example.com");
assert!(result.is_err());
Setup username to user1
use url::{Url, ParseError};
let mut url = Url::parse("ftp://:secre1@example.com/")?;
let result = url.set_username("user1");
assert!(result.is_ok());
assert_eq!(url.username(), "user1");
assert_eq!(url.as_str(), "ftp://user1:secre1@example.com/");
sourcepub fn set_scheme(&mut self, scheme: &str) -> Result<(), ()>
pub fn set_scheme(&mut self, scheme: &str) -> Result<(), ()>
Change this URL’s scheme.
Do nothing and return Err
under the following circumstances:
- If the new scheme is not in
[a-zA-Z][a-zA-Z0-9+.-]+
- If this URL is cannot-be-a-base and the new scheme is one of
http
,https
,ws
,wss
orftp
- If either the old or new scheme is
http
,https
,ws
,wss
orftp
and the other is not one of these - If the new scheme is
file
and this URL includes credentials or has a non-null port - If this URL’s scheme is
file
and its host is empty or null
See also the URL specification’s section on legal scheme state overrides.
Examples
Change the URL’s scheme from https
to foo
:
use url::Url;
let mut url = Url::parse("https://example.net")?;
let result = url.set_scheme("http");
assert_eq!(url.as_str(), "http://example.net/");
assert!(result.is_ok());
Change the URL’s scheme from foo
to bar
:
use url::Url;
let mut url = Url::parse("foo://example.net")?;
let result = url.set_scheme("bar");
assert_eq!(url.as_str(), "bar://example.net");
assert!(result.is_ok());
Cannot change URL’s scheme from https
to foõ
:
use url::Url;
let mut url = Url::parse("https://example.net")?;
let result = url.set_scheme("foõ");
assert_eq!(url.as_str(), "https://example.net/");
assert!(result.is_err());
Cannot change URL’s scheme from mailto
(cannot-be-a-base) to https
:
use url::Url;
let mut url = Url::parse("mailto:rms@example.net")?;
let result = url.set_scheme("https");
assert_eq!(url.as_str(), "mailto:rms@example.net");
assert!(result.is_err());
Cannot change the URL’s scheme from foo
to https
:
use url::Url;
let mut url = Url::parse("foo://example.net")?;
let result = url.set_scheme("https");
assert_eq!(url.as_str(), "foo://example.net");
assert!(result.is_err());
Cannot change the URL’s scheme from http
to foo
:
use url::Url;
let mut url = Url::parse("http://example.net")?;
let result = url.set_scheme("foo");
assert_eq!(url.as_str(), "http://example.net/");
assert!(result.is_err());
sourcepub fn from_file_path<P>(path: P) -> Result<Url, ()> where
P: AsRef<Path>,
pub fn from_file_path<P>(path: P) -> Result<Url, ()> where
P: AsRef<Path>,
Convert a file name as std::path::Path
into an URL in the file
scheme.
This returns Err
if the given path is not absolute or,
on Windows, if the prefix is not a disk prefix (e.g. C:
) or a UNC prefix (\\
).
Examples
On Unix-like platforms:
use url::Url;
let url = Url::from_file_path("/tmp/foo.txt")?;
assert_eq!(url.as_str(), "file:///tmp/foo.txt");
let url = Url::from_file_path("../foo.txt");
assert!(url.is_err());
let url = Url::from_file_path("https://google.com/");
assert!(url.is_err());
sourcepub fn from_directory_path<P>(path: P) -> Result<Url, ()> where
P: AsRef<Path>,
pub fn from_directory_path<P>(path: P) -> Result<Url, ()> where
P: AsRef<Path>,
Convert a directory name as std::path::Path
into an URL in the file
scheme.
This returns Err
if the given path is not absolute or,
on Windows, if the prefix is not a disk prefix (e.g. C:
) or a UNC prefix (\\
).
Compared to from_file_path
, this ensure that URL’s the path has a trailing slash
so that the entire path is considered when using this URL as a base URL.
For example:
"index.html"
parsed withUrl::from_directory_path(Path::new("/var/www"))
as the base URL isfile:///var/www/index.html
"index.html"
parsed withUrl::from_file_path(Path::new("/var/www"))
as the base URL isfile:///var/index.html
, which might not be what was intended.
Note that std::path
does not consider trailing slashes significant
and usually does not include them (e.g. in Path::parent()
).
sourcepub fn to_file_path(&self) -> Result<PathBuf, ()>
pub fn to_file_path(&self) -> Result<PathBuf, ()>
Assuming the URL is in the file
scheme or similar,
convert its path to an absolute std::path::Path
.
Note: This does not actually check the URL’s scheme
,
and may give nonsensical results for other schemes.
It is the user’s responsibility to check the URL’s scheme before calling this.
let path = url.to_file_path();
Returns Err
if the host is neither empty nor "localhost"
(except on Windows, where
file:
URLs may have a non-local host),
or if Path::new_opt()
returns None
.
(That is, if the percent-decoded path contains a NUL byte or,
for a Windows path, is not UTF-8.)
Trait Implementations
sourceimpl FromStr for Url
impl FromStr for Url
Parse a string as an URL, without a base URL or encoding override.
type Err = ParseError
type Err = ParseError
The associated error which can be returned from parsing.
sourceimpl Ord for Url
impl Ord for Url
URLs compare like their serialization.
sourceimpl PartialOrd<Url> for Url
impl PartialOrd<Url> for Url
URLs compare like their serialization.
sourcefn partial_cmp(&self, other: &Url) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Url
URLs compare like their serialization.
Auto Trait Implementations
impl RefUnwindSafe for Url
impl Send for Url
impl Sync for Url
impl Unpin for Url
impl UnwindSafe for Url
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> FmtForward for T
impl<T> FmtForward for T
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Causes self
to use its Binary
implementation when Debug
-formatted.
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Causes self
to use its Display
implementation when
Debug
-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Causes self
to use its LowerExp
implementation when
Debug
-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self
to use its LowerHex
implementation when
Debug
-formatted. Read more
fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
Causes self
to use its Octal
implementation when Debug
-formatted.
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Causes self
to use its Pointer
implementation when
Debug
-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Causes self
to use its UpperExp
implementation when
Debug
-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self
to use its UpperHex
implementation when
Debug
-formatted. Read more
impl<T> Pipe for T where
T: ?Sized,
impl<T> Pipe for T where
T: ?Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
Pipes by value. This is generally the method you want to use. Read more
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
Borrows self
and passes that borrow into the pipe function. Read more
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
Mutably borrows self
and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.borrow()
into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.borrow_mut()
into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.as_ref()
into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.as_mut()
into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.deref()
into the pipe function.
impl<T> PipeAsRef for T
impl<T> PipeAsRef for T
fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: AsRef<T>,
T: 'a,
R: 'a,
fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: AsRef<T>,
T: 'a,
R: 'a,
Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
fn pipe_as_mut<'a, T, R>(&'a mut self, func: impl FnOnce(&'a mut T) -> R) -> R where
Self: AsMut<T>,
T: 'a,
R: 'a,
fn pipe_as_mut<'a, T, R>(&'a mut self, func: impl FnOnce(&'a mut T) -> R) -> R where
Self: AsMut<T>,
T: 'a,
R: 'a,
Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
impl<T> PipeBorrow for T
impl<T> PipeBorrow for T
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
T: 'a,
R: 'a,
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
T: 'a,
R: 'a,
Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
fn pipe_borrow_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: BorrowMut<T>,
T: 'a,
R: 'a,
fn pipe_borrow_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: BorrowMut<T>,
T: 'a,
R: 'a,
Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
impl<T> PipeDeref for T
impl<T> PipeDeref for T
fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
Self: Deref,
R: 'a,
fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
Self: Deref,
R: 'a,
Pipes a dereference into a function that cannot normally be called in suffix position. Read more
fn pipe_deref_mut<'a, R>(
&'a mut self,
func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
Self: DerefMut,
R: 'a,
fn pipe_deref_mut<'a, R>(
&'a mut self,
func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
Self: DerefMut,
R: 'a,
Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more
impl<T> PipeRef for T
impl<T> PipeRef for T
impl<T> Tap for T
impl<T> Tap for T
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B>
of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B>
of a value. Read more
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Immutable access to the AsRef<R>
view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Mutable access to the AsMut<R>
view of a value. Read more
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
Immutable access to the Deref::Target
of a value. Read more
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Mutable access to the Deref::Target
of a value. Read more
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls .tap()
only in debug builds, and is erased in release builds.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more
impl<T> Tap for T
impl<T> Tap for T
fn tap<F, R>(self, func: F) -> Self where
F: FnOnce(&Self) -> R,
fn tap<F, R>(self, func: F) -> Self where
F: FnOnce(&Self) -> R,
Provides immutable access for inspection. Read more
fn tap_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&Self) -> R,
fn tap_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&Self) -> R,
Calls tap
in debug builds, and does nothing in release builds.
fn tap_mut<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
fn tap_mut<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
Provides mutable access for modification. Read more
fn tap_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
fn tap_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
Calls tap_mut
in debug builds, and does nothing in release builds.
impl<T, U> TapAsRef<U> for T where
U: ?Sized,
impl<T, U> TapAsRef<U> for T where
U: ?Sized,
fn tap_ref<F, R>(self, func: F) -> Self where
Self: AsRef<T>,
F: FnOnce(&T) -> R,
fn tap_ref<F, R>(self, func: F) -> Self where
Self: AsRef<T>,
F: FnOnce(&T) -> R,
Provides immutable access to the reference for inspection.
fn tap_ref_dbg<F, R>(self, func: F) -> Self where
Self: AsRef<T>,
F: FnOnce(&T) -> R,
fn tap_ref_dbg<F, R>(self, func: F) -> Self where
Self: AsRef<T>,
F: FnOnce(&T) -> R,
Calls tap_ref
in debug builds, and does nothing in release builds.
fn tap_ref_mut<F, R>(self, func: F) -> Self where
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_ref_mut<F, R>(self, func: F) -> Self where
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
Provides mutable access to the reference for modification.
fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self where
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self where
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
Calls tap_ref_mut
in debug builds, and does nothing in release builds.
impl<T, U> TapBorrow<U> for T where
U: ?Sized,
impl<T, U> TapBorrow<U> for T where
U: ?Sized,
fn tap_borrow<F, R>(self, func: F) -> Self where
Self: Borrow<T>,
F: FnOnce(&T) -> R,
fn tap_borrow<F, R>(self, func: F) -> Self where
Self: Borrow<T>,
F: FnOnce(&T) -> R,
Provides immutable access to the borrow for inspection. Read more
fn tap_borrow_dbg<F, R>(self, func: F) -> Self where
Self: Borrow<T>,
F: FnOnce(&T) -> R,
fn tap_borrow_dbg<F, R>(self, func: F) -> Self where
Self: Borrow<T>,
F: FnOnce(&T) -> R,
Calls tap_borrow
in debug builds, and does nothing in release builds.
fn tap_borrow_mut<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_borrow_mut<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Provides mutable access to the borrow for modification.
fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Calls tap_borrow_mut
in debug builds, and does nothing in release
builds. Read more
impl<T> TapDeref for T
impl<T> TapDeref for T
fn tap_deref<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
fn tap_deref<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Immutably dereferences self
for inspection.
fn tap_deref_dbg<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
fn tap_deref_dbg<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Calls tap_deref
in debug builds, and does nothing in release builds.
fn tap_deref_mut<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
fn tap_deref_mut<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Mutably dereferences self
for modification.
fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Calls tap_deref_mut
in debug builds, and does nothing in release
builds. Read more