web_url/url/
web_url.rs

1use address::IPAddress;
2
3/// A web-based URL.
4///
5/// # Format
6/// All web-based URLs will be in the format: `scheme://host:port/path?query#fragment`.
7/// This is a sub-set of [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986#section-4.3).
8///
9/// The port, query, and fragment are all optional.
10/// The path will never be empty and will always start with a '/'.
11#[derive(Clone, Debug)]
12pub struct WebUrl {
13    pub(in crate::url) url: String,
14    pub(in crate::url) scheme_len: u32,
15    pub(in crate::url) host_end: u32,
16    pub(in crate::url) ip: Option<IPAddress>,
17    pub(in crate::url) port_end: u32,
18    pub(in crate::url) port: Option<u16>,
19    pub(in crate::url) path_end: u32,
20    pub(in crate::url) query_end: u32,
21}
22
23impl WebUrl {
24    //! Construction
25
26    /// Creates a new web-based URL.
27    ///
28    /// # Safety
29    /// The parameters must be valid.
30    #[allow(clippy::too_many_arguments)]
31    pub unsafe fn new<S>(
32        url: S,
33        scheme_len: u32,
34        host_end: u32,
35        ip: Option<IPAddress>,
36        port_end: u32,
37        port: Option<u16>,
38        path_end: u32,
39        query_end: u32,
40    ) -> Self
41    where
42        S: Into<String>,
43    {
44        Self {
45            url: url.into(),
46            scheme_len,
47            host_end,
48            ip,
49            port_end,
50            port,
51            path_end,
52            query_end,
53        }
54    }
55}
56
57impl WebUrl {
58    //! Properties
59
60    /// Gets the length.
61    pub fn len(&self) -> usize {
62        self.url.len()
63    }
64
65    /// Checks if the url is empty.
66    pub fn is_empty(&self) -> bool {
67        false
68    }
69}