Skip to main content

ConnectionUrl

Struct ConnectionUrl 

Source
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>

Source

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.

Source

pub fn as_str(&self) -> &'a str

Returns the connection URL exactly as supplied.

Source

pub fn scheme(&self) -> &'a str

Returns the URL scheme without the trailing colon.

Source

pub fn has_scheme(&self, expected: &str) -> bool

Returns true when the URL uses expected.

URL schemes are ASCII case-insensitive.

Source

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.

Source

pub fn decoded_path(&self) -> Result<Cow<'a, str>>

Returns the percent-decoded path component.

Source

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.

Source

pub fn username(&self) -> Result<Option<Cow<'a, str>>>

Returns the percent-decoded username from the authority component.

Source

pub fn password(&self) -> Option<Cow<'a, [u8]>>

Returns the percent-decoded password bytes from the authority component.

Source

pub fn host(&self) -> Result<Option<&'a str>>

Returns the host from the authority component.

Brackets around an IPv6 address are not included.

Source

pub fn port(&self) -> Result<Option<u16>>

Returns the port from the authority component.

Source

pub fn validate_authority(&self) -> Result<()>

Validates the host and port syntax of an authority component.

URLs without an authority component are valid.

Source

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.

Source

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>

Source§

fn clone(&self) -> ConnectionUrl<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ConnectionUrl<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for ConnectionUrl<'a>

Source§

fn eq(&self, other: &ConnectionUrl<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Copy for ConnectionUrl<'a>

Source§

impl<'a> Eq for ConnectionUrl<'a>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more