pub struct Url(/* private fields */);Expand description
An OCPI URL.
The text is stored exactly as received. A URL is an identifier as much as a location: a
peer that registered https://example.com/ocpi/cpo/2.3.0 must see that string again, not the
https://example.com/ocpi/cpo/2.3.0 that a normalising parser would hand back with a
re-encoded path or an added trailing slash. Url::parse gives the parsed form when it is
needed for making a request.
use ocpi_kit::types::Url;
let url = Url::new("https://example.com/ocpi/cpo/2.3.0/locations").unwrap();
assert_eq!(url.as_str(), "https://example.com/ocpi/cpo/2.3.0/locations");
assert_eq!(url.parse().unwrap().host_str(), Some("example.com"));Spec: 2.3.0 §types_url_type
Implementations§
Source§impl Url
impl Url
Sourcepub fn new(value: impl Into<String>) -> Result<Self, InvalidUrl>
pub fn new(value: impl Into<String>) -> Result<Self, InvalidUrl>
Creates a Url, checking that it parses as an absolute URL and fits string(255).
§Errors
Returns InvalidUrl if the text is not an absolute URL or is longer than 255
characters.
Sourcepub fn new_lenient(value: impl Into<String>) -> Self
pub fn new_lenient(value: impl Into<String>) -> Self
Creates a Url without checking anything. Used by Deserialize.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consumes this value and yields the inner text.
Sourcepub fn parse(&self) -> Result<Url, InvalidUrl>
pub fn parse(&self) -> Result<Url, InvalidUrl>
Parses the URL.
§Errors
Returns InvalidUrl if the stored text is not a URL. This can only happen for values
that came off the wire, since Url::new checks up front.
Sourcepub fn join(&self, segment: &str) -> Self
pub fn join(&self, segment: &str) -> Self
This URL with a path segment appended, keeping exactly one / between the two.
Endpoint URLs discovered from a peer sometimes carry a trailing slash and sometimes do not; this joins correctly either way and never emits a double slash or a trailing one.
use ocpi_kit::types::Url;
let base = Url::new("https://example.com/ocpi/cpo/2.3.0/locations/").unwrap();
assert_eq!(base.join("NL").join("TNM").as_str(),
"https://example.com/ocpi/cpo/2.3.0/locations/NL/TNM");Sourcepub fn with_query(&self, query: &str) -> Self
pub fn with_query(&self, query: &str) -> Self
This URL with a query string appended, using ? or & as appropriate.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Url
impl<'de> Deserialize<'de> for Url
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for Url
Source§impl JsonSchema for Url
Available on crate feature schema only.
impl JsonSchema for Url
schema only.Source§fn json_schema(_g: &mut SchemaGenerator) -> Schema
fn json_schema(_g: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for Url
impl Ord for Url
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Url
impl PartialOrd 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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.