Struct Utils

Source
pub struct Utils;

Implementationsยง

Sourceยง

impl Utils

Source

pub fn substring_after_scheme<'a>(parser: &Parser, input: &'a str) -> &'a str

Get substring immediately after scheme.

ยงExample
use url_parse::utils::Utils;
use url_parse::core::Parser;
let input =
    "https://user:pass@www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let expected =
    "user:pass@www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone".to_string();
let parser = Parser::new(None);
let result = Utils::substring_after_scheme(&parser, input);
assert_eq!(result, expected);
Source

pub fn substring_after_login<'a>(parser: &Parser, input: &'a str) -> &'a str

Get substring immediately after login. Eliminates scheme to ensure no colon present in remainder.

ยงExample
use url_parse::utils::Utils;
use url_parse::core::Parser;
let input =
    "https://user:pass@www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let expected = "www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone".to_string();
let parser = Parser::new(None);
let result = Utils::substring_after_login(&parser, input);
assert_eq!(result, expected);
Source

pub fn substring_after_port<'a>(parser: &Parser, input: &'a str) -> &'a str

Get substring immediately after port. Eliminates scheme to ensure no colon present in remainder.

ยงExample
use url_parse::utils::Utils;
use url_parse::core::Parser;
let input =
    "https://user:pass@www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let expected = "www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone".to_string();
let parser = Parser::new(None);
let result = Utils::substring_after_login(&parser, input);
assert_eq!(result, expected);
Source

pub fn substring_before_port<'a>(parser: &Parser, input: &'a str) -> &'a str

Get substring immediately before port.

ยงExample
use url_parse::utils::Utils;
use url_parse::core::Parser;
let input = "https://www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let expected = "https://www.example.co.uk".to_string();
let parser = Parser::new(None);
let result = Utils::substring_before_port(&parser, input);
assert_eq!(result, expected);
Source

pub fn substring_from_path_begin<'a>( parser: &Parser, input: &'a str, ) -> Option<&'a str>

Get substring starting at path field. Eliminates scheme to ensure no colon present in remainder.

ยงExample
use url_parse::utils::Utils;
use url_parse::core::Parser;
let input =
    "https://user:pass@www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let expected =
    "/blog/article/search?docid=720&hl=en#dayone".to_string();
let parser = Parser::new(None);
let result = Utils::substring_from_path_begin(&parser, input).unwrap_or("");
assert_eq!(result, expected);
Source

pub fn canonicalize<'a>( parser: &Parser, input: &'a str, subpath: &'a str, ) -> String

Partially matches a subpath in a path. Useful for i.e. GitHub absolute paths from URL hrefs.

ยงExample
use url_parse::utils::Utils;
use url_parse::core::Parser;
let input = "https://github.com/mihaigalos/aim/releases/tag/1.5.4";
let subpath = "mihaigalos/aim/releases/download/1.5.4/aim-1.5.4-x86_64-unknown-linux-gnu.tar.gz";
let expected = "https://github.com/mihaigalos/aim/releases/download/1.5.4/aim-1.5.4-x86_64-unknown-linux-gnu.tar.gz";
let result = Utils::canonicalize(&Parser::new(None), input, subpath);
assert_eq!(result, expected);

Auto Trait Implementationsยง

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.