iref_core/iri/
authority_mut.rs

1use std::ops::Deref;
2
3use crate::common::authority_mut::AuthorityMutImpl;
4
5use super::{Authority, Host, Port, UserInfo};
6
7pub struct AuthorityMut<'a>(AuthorityMutImpl<'a, Authority>);
8
9impl<'a> Deref for AuthorityMut<'a> {
10	type Target = Authority;
11
12	fn deref(&self) -> &Self::Target {
13		self.as_authority()
14	}
15}
16
17impl<'a> AuthorityMut<'a> {
18	/// Creates a new mutable authority part.
19	///
20	/// # Safety
21	///
22	/// The buffer content between the range `start..end` must be a valid
23	/// authority.
24	pub unsafe fn new(buffer: &'a mut Vec<u8>, start: usize, end: usize) -> Self {
25		Self(AuthorityMutImpl::new(buffer, start, end))
26	}
27
28	pub(crate) fn from_impl(i: AuthorityMutImpl<'a, Authority>) -> Self {
29		Self(i)
30	}
31
32	#[inline]
33	pub fn as_authority(&self) -> &Authority {
34		self.0.as_authority()
35	}
36
37	#[inline]
38	pub fn into_authority(self) -> &'a Authority {
39		self.0.into_authority()
40	}
41
42	#[inline]
43	pub fn set_userinfo(&mut self, userinfo: Option<&UserInfo>) {
44		self.0.set_userinfo(userinfo)
45	}
46
47	#[inline]
48	pub fn set_host(&mut self, host: &Host) {
49		self.0.set_host(host)
50	}
51
52	#[inline]
53	pub fn set_port(&mut self, port: Option<&Port>) {
54		self.0.set_port(port)
55	}
56}
57
58#[cfg(test)]
59mod tests {
60	use crate::Iri;
61
62	#[test]
63	fn explicit_empty_with_authority_alike_path() {
64		let iri = Iri::new("scheme:////").unwrap();
65		let authority = iri.authority();
66
67		assert!(authority.unwrap().is_empty());
68	}
69}