UserInfo

Struct UserInfo 

Source
pub struct UserInfo<'url> { /* private fields */ }
Expand description

Represents user information (username and password) in a URL.

This struct stores the credentials that may be present in a URL’s authority component. It supports both ASCII and UTF-8 characters in usernames and passwords.

§Examples

use faup_rs::{Url, UserInfo};

// Parse a URL with user info
let url = Url::parse("https://user:pass@example.com").unwrap();
let user_info = url.userinfo().unwrap();

// Access username and password
assert_eq!(user_info.username(), "user");
assert_eq!(user_info.password(), Some("pass"));

// Parse a URL with only username
let url = Url::parse("https://user@example.com").unwrap();
let user_info = url.userinfo().unwrap();
assert_eq!(user_info.username(), "user");
assert_eq!(user_info.password(), None);

// Parse a URL with UTF-8 user info
let url = Url::parse("https://用户:密码@example.com").unwrap();
let user_info = url.userinfo().unwrap();
assert_eq!(user_info.username(), "用户");
assert_eq!(user_info.password(), Some("密码"));

Implementations§

Source§

impl UserInfo<'_>

Source

pub fn username(&self) -> &str

Returns the username component of the user information.

§Returns
  • &str - The username.
§Examples
use faup_rs::Url;

let url = Url::parse("https://user@example.com").unwrap();
assert_eq!(url.userinfo().unwrap().username(), "user");

// UTF-8 username
let url = Url::parse("https://用户@example.com").unwrap();
assert_eq!(url.userinfo().unwrap().username(), "用户");
Source

pub fn password(&self) -> Option<&str>

Returns the password component of the user information, if present.

§Returns
  • Option<&str> - The password, or None if not present.
§Examples
use faup_rs::Url;

// With password
let url = Url::parse("https://user:pass@example.com").unwrap();
assert_eq!(url.userinfo().unwrap().password(), Some("pass"));

// Without password
let url = Url::parse("https://user@example.com").unwrap();
assert_eq!(url.userinfo().unwrap().password(), None);

// UTF-8 password
let url = Url::parse("https://user:密码@example.com").unwrap();
assert_eq!(url.userinfo().unwrap().password(), Some("密码"));

Trait Implementations§

Source§

impl<'url> Debug for UserInfo<'url>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'url> Freeze for UserInfo<'url>

§

impl<'url> RefUnwindSafe for UserInfo<'url>

§

impl<'url> Send for UserInfo<'url>

§

impl<'url> Sync for UserInfo<'url>

§

impl<'url> Unpin for UserInfo<'url>

§

impl<'url> UnwindSafe for UserInfo<'url>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.