pub struct ConnectionUrl<'a> { /* private fields */ }Expand description
A parsed database connection URL.
Connection URLs use the common <scheme>:<target>?<query> form, but the
target is interpreted by the selected database driver. Network drivers use
the conventional //user:password@host:port/path target. File-backed
drivers use file_path, which treats // as an optional
marker and keeps the following text as the path.
This distinction allows connection strings such as sqlite://todos.db and
sqlite://:memory: without interpreting todos.db or :memory: as a host.
Implementations§
Source§impl<'a> ConnectionUrl<'a>
impl<'a> ConnectionUrl<'a>
Sourcepub fn parse(value: &'a str) -> Result<Self>
pub fn parse(value: &'a str) -> Result<Self>
Parses a database connection URL.
This validates the scheme. Drivers validate the target and query parameters they support.
Sourcepub fn has_scheme(&self, expected: &str) -> bool
pub fn has_scheme(&self, expected: &str) -> bool
Returns true when the URL uses expected.
URL schemes are ASCII case-insensitive.
Sourcepub fn path(&self) -> &'a str
pub fn path(&self) -> &'a str
Returns the path component of an authority-based connection URL.
For postgresql://localhost/mydb, this returns /mydb. Use
file_path for SQLite and other file-backed drivers.
Sourcepub fn decoded_path(&self) -> Result<Cow<'a, str>>
pub fn decoded_path(&self) -> Result<Cow<'a, str>>
Returns the percent-decoded path component.
Sourcepub fn file_path(&self) -> Result<PathBuf>
pub fn file_path(&self) -> Result<PathBuf>
Returns the file path named by a file-backed connection URL.
The optional // after the scheme is discarded, a query string is not
part of the path, and # remains a normal filename character. The path
is percent-decoded before it is returned.
Sourcepub fn username(&self) -> Result<Option<Cow<'a, str>>>
pub fn username(&self) -> Result<Option<Cow<'a, str>>>
Returns the percent-decoded username from the authority component.
Sourcepub fn password(&self) -> Option<Cow<'a, [u8]>>
pub fn password(&self) -> Option<Cow<'a, [u8]>>
Returns the percent-decoded password bytes from the authority component.
Sourcepub fn host(&self) -> Result<Option<&'a str>>
pub fn host(&self) -> Result<Option<&'a str>>
Returns the host from the authority component.
Brackets around an IPv6 address are not included.
Validates the host and port syntax of an authority component.
URLs without an authority component are valid.
Sourcepub fn query_pairs(
&self,
) -> impl Iterator<Item = (Cow<'a, str>, Cow<'a, str>)> + '_
pub fn query_pairs( &self, ) -> impl Iterator<Item = (Cow<'a, str>, Cow<'a, str>)> + '_
Iterates over the percent-decoded query parameters.
Query components use form encoding, so + decodes to a space.
Sourcepub fn redact_password(&self) -> Cow<'a, str>
pub fn redact_password(&self) -> Cow<'a, str>
Returns the URL with an authority password replaced by ***.
Trait Implementations§
Source§impl<'a> Clone for ConnectionUrl<'a>
impl<'a> Clone for ConnectionUrl<'a>
Source§fn clone(&self) -> ConnectionUrl<'a>
fn clone(&self) -> ConnectionUrl<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for ConnectionUrl<'a>
impl<'a> Debug for ConnectionUrl<'a>
Source§impl<'a> PartialEq for ConnectionUrl<'a>
impl<'a> PartialEq for ConnectionUrl<'a>
Source§fn eq(&self, other: &ConnectionUrl<'a>) -> bool
fn eq(&self, other: &ConnectionUrl<'a>) -> bool
self and other values to be equal, and is used by ==.impl<'a> Copy for ConnectionUrl<'a>
impl<'a> Eq for ConnectionUrl<'a>
impl<'a> StructuralPartialEq for ConnectionUrl<'a>
Auto Trait Implementations§
impl<'a> Freeze for ConnectionUrl<'a>
impl<'a> RefUnwindSafe for ConnectionUrl<'a>
impl<'a> Send for ConnectionUrl<'a>
impl<'a> Sync for ConnectionUrl<'a>
impl<'a> Unpin for ConnectionUrl<'a>
impl<'a> UnsafeUnpin for ConnectionUrl<'a>
impl<'a> UnwindSafe for ConnectionUrl<'a>
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.