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<'_>
impl UserInfo<'_>
Sourcepub fn username(&self) -> &str
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(), "用户");
Sourcepub fn password(&self) -> Option<&str>
pub fn password(&self) -> Option<&str>
Returns the password component of the user information, if present.
§Returns
Option<&str>
- The password, orNone
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§
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> 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
Mutably borrows from an owned value. Read more