BaseInfo

Enum BaseInfo 

Source
pub enum BaseInfo {
    None,
    NoRoot(Url),
    Full(Url, String),
}
Expand description

Information used for resolving relative URLs within a particular input source. There should be a 1:1 correspondence between each BaseInfo and its originating InputSource. The main entry point for constructing is BaseInfo::from_source_url.

Once constructed, BaseInfo::parse_url_text can be used to parse and resolve a (possibly relative) URL obtained from within the associated InputSource.

A BaseInfo may be built from input sources which cannot resolve relative links—for instance, stdin. It may also be built from input sources which can resolve locally-relative links, but not root-relative links.

Variants§

§

None

No base information is available. This is for sources with no base information, such as [ResolvedInputSource::Stdin], and for URLs which cannot be a base, such as data: and tel:. BaseInfo::None can resolve no relative links; only fully-qualified links will be parsed successfully.

§

NoRoot(Url)

A base which cannot resolve root-relative links. This is for file: URLs where the root directory is not known. As such, you can traverse relative to the current URL (by traversing the filesystem), but you cannot jump to the “root”.

§

Full(Url, String)

A full base made up of origin and path. This can resolve all kinds of relative links.

All non-file: URLs which can be a base fall into this case. For these, origin and path are obtained by dividing the source URL into its origin and path. When joined, ${origin}/${path} should be equivalent to the source’s original URL.

This also represents file: URLs with a known root. The origin field records the file: URL which will be used to resolve root-relative links. The path field is the subpath to a particular input source within the root. This is retained to resolve locally-relative links.

Implementations§

Source§

impl BaseInfo

Source

pub const fn none() -> Self

Constructs BaseInfo::None.

Source

pub const fn full(origin: Url, path: String) -> Self

Constructs BaseInfo::Full with the given fields.

Source

pub fn from_source_url(url: &Url) -> Self

Constructs a BaseInfo, with the variant being determined by the given URL.

Compared to BaseInfo::from_base_url, this function is more lenient in what it accepts because this function should return a result for all input source URLs.

Source

fn split_url_origin_and_path(url: &Url) -> Option<(Url, String)>

Split URL into its origin and path, if possible. Will fail and return None for URLs which cannot be a base.

Source

pub fn from_base_url(url: &Url) -> Result<BaseInfo, ErrorKind>

Constructs a BaseInfo from the given URL, requiring that the given path be acceptable as a base URL. That is, it cannot be a special scheme like data:.

§Errors

Errors if the given URL cannot be a base.

Source

pub fn from_path(path: &Path) -> Result<BaseInfo, ErrorKind>

Constructs a BaseInfo from the given filesystem path, requiring that the given path be absolute. Assumes that the given path represents a directory.

This constructs a BaseInfo::Full where root-relative links will go to the given path.

§Errors

Errors if the given path is not an absolute path.

Source

pub fn use_fs_root_as_origin(&self) -> Cow<'_, Self>

If this is a BaseInfo::NoRoot, promote it to a BaseInfo::Full by using the filesystem root as the “origin” for root-relative links. Root-relative links will go to the filesystem root.

Generally, this function should be avoided in favour of a more explicit user-provided root directory. The filesystem root is rarely a good place to look for files.

Makes no change to other BaseInfo variants.

§Panics

If unable to split a BaseInfo::NoRoot into origin and path.

Source

pub fn use_fs_path_as_origin(&self) -> Cow<'_, Self>

If this is a BaseInfo::NoRoot, promote it to a BaseInfo::Full by using the entire filesystem path as the “origin” for root-relative links. Root-relative links will go to the URL that was previously within NoRoot.

Generally, this function should be avoided in favour of a more explicit user-provided root directory.

Makes no change to other BaseInfo variants.

Source

pub fn url(&self) -> Option<Url>

Returns the URL for the current BaseInfo, joining the origin and path if needed.

Source

pub fn to_file_path(&self) -> Option<PathBuf>

Returns the filesystem path for the current BaseInfo if the underlying URL is a file: URL.

Source

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

Returns the scheme of the underlying URL.

Source

pub const fn is_none(&self) -> bool

Returns whether this value is BaseInfo::None.

Source

pub const fn supports_root_relative(&self) -> bool

Returns whether this BaseInfo variant supports resolving root-relative links.

If true, implies BaseInfo::supports_locally_relative.

Source

pub const fn supports_locally_relative(&self) -> bool

Returns whether this BaseInfo variant supports resolving locally-relative links.

Source

pub const fn or_fallback<'a>(&'a self, fallback: &'a Self) -> &'a Self

Returns the BaseInfo which has more information between self and the given fallback.

BaseInfo::Full is preferred over BaseInfo::NoRoot which is preferred over BaseInfo::None. If both self and fallback are the same variant, then self will be preferred.

Source

pub fn parse_url_text(&self, text: &str) -> Result<Url, ErrorKind>

Parses the given URL text into a fully-qualified URL, including resolving relative links if supported by the current BaseInfo.

To resolve relative links, this uses Url::join and ReqwestUrlExt::join_rooted for BaseInfo::NoRoot and BaseInfo::Full, respectively.

§Errors

Returns an error if the text is an invalid URL, or if the text is a relative link and this BaseInfo variant cannot resolve the relative link.

Source

pub fn parse_url_text_with_root_dir( &self, text: &str, root_dir: Option<&Url>, ) -> Result<Url, ErrorKind>

Parses the given URL text into a fully-qualified URL, including resolving relative links if supported by the current BaseInfo and applying the given root-dir if necessary.

The root-dir is applied if the current BaseInfo is BaseInfo::None or has a file: URL and if the given text is a root-relative link. In these cases, the given root_dir will take effect instead of the original BaseInfo.

§Errors

Propagates errors from BaseInfo::parse_url_text.

Trait Implementations§

Source§

impl Clone for BaseInfo

Source§

fn clone(&self) -> BaseInfo

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BaseInfo

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for BaseInfo

Source§

fn default() -> BaseInfo

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for BaseInfo

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for BaseInfo

Source§

fn eq(&self, other: &BaseInfo) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&str> for BaseInfo

Source§

fn try_from(value: &str) -> Result<Self, ErrorKind>

Attempts to parse a base from the given string which may be a URL or a filesystem path. In both cases, the string must represent a valid base (i.e., not resulting in BaseInfo::None). Otherwise, an error will be returned.

Note that this makes a distinction between filesystem paths as paths and filesystem paths as URLs. When specified as a path, they will become BaseInfo::Full but when specified as a URL, they will become BaseInfo::NoRoot.

Additionally, the empty string is accepted and will be parsed to BaseInfo::None.

Source§

type Error = ErrorKind

The type returned in the event of a conversion error.
Source§

impl TryFrom<String> for BaseInfo

Source§

type Error = ErrorKind

The type returned in the event of a conversion error.
Source§

fn try_from(value: String) -> Result<Self, ErrorKind>

Performs the conversion.
Source§

impl Eq for BaseInfo

Source§

impl StructuralPartialEq for BaseInfo

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromResponse for T

§

fn from_response<'async_trait, B>( response: Response<B>, ) -> Pin<Box<dyn Future<Output = Result<T, Error>> + Send + 'async_trait>>
where B: Body<Data = Bytes, Error = Error> + Send + 'async_trait, T: 'async_trait,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,