Skip to main content

FileChecker

Struct FileChecker 

Source
pub(crate) struct FileChecker {
    base: Option<Base>,
    fallback_extensions: Vec<String>,
    index_files: Option<Vec<String>>,
    include_fragments: bool,
    fragment_checker: FragmentChecker,
    wikilink_resolver: Option<WikilinkResolver>,
}
Expand description

A utility for checking the existence and validity of file-based URIs.

FileChecker resolves and validates file paths, handling both absolute and relative paths. It supports base path resolution, fallback extensions for files without extensions, and optional fragment checking for HTML files.

Fields§

§base: Option<Base>

Base path or URL used for resolving relative paths.

§fallback_extensions: Vec<String>

List of file extensions to try if the original path doesn’t exist.

§index_files: Option<Vec<String>>

If specified, resolves to one of the given index files if the original path is a directory.

If non-None, a directory must contain at least one of the file names in order to be considered a valid link target. Index files names are required to match regular files, aside from the special . name which will match the directory itself.

If None, index file checking is disabled and directory links are valid as long as the directory exists on disk.

§include_fragments: bool

Whether to check for the existence of fragments (e.g., #section-id) in HTML files.

§fragment_checker: FragmentChecker

Utility for performing fragment checks in HTML files.

§wikilink_resolver: Option<WikilinkResolver>

Utility for optionally resolving Wikilinks.

Implementations§

Source§

impl FileChecker

Source

pub(crate) fn new( base: Option<Base>, fallback_extensions: Vec<String>, index_files: Option<Vec<String>>, include_fragments: bool, include_wikilinks: bool, ) -> Result<Self>

Creates a new FileChecker with the given configuration.

§Arguments
  • base - Optional base path or URL for resolving relative paths.
  • fallback_extensions - List of extensions to try if the original file is not found.
  • index_files - Optional list of index file names to search for if the path is a directory.
  • include_fragments - Whether to check for fragment existence in HTML files.
  • include_wikilinks - Whether to check the existence of Wikilinks found in Markdown files .
§Errors

Fails if an invalid base is provided when including wikilinks.

Source

pub(crate) async fn check(&self, uri: &Uri) -> Status

Checks the given file URI for existence and validity.

This method resolves the URI to a file path, checks if the file exists, and optionally checks for the existence of fragments in HTML files.

§Arguments
  • uri - The URI to check.
§Returns

Returns a Status indicating the result of the check.

Source

fn resolve_base(&self, path: &Path) -> PathBuf

Resolves the given path using the base path, if one is set.

§Arguments
  • path - The path to resolve.
§Returns

Returns the resolved path as a PathBuf, or the original path if no base path is defined.

Source

fn resolve_local_path<'a>( &self, path: &'a Path, uri: &Uri, ) -> Result<Cow<'a, Path>>

Resolves the given local path by applying logic which is specific to local file checking - currently, this includes fallback extensions and index files.

§Arguments
  • path - The path to check. Need not exist.
  • uri - The original URI, used for error reporting.
§Returns

Returns Ok with the resolved path if it is valid, otherwise returns Err with an appropriate error. The returned path, if any, is guaranteed to exist and may be a file or a directory.

Source

fn apply_fallback_extensions(&self, path: &Path, uri: &Uri) -> Result<PathBuf>

Resolves a path to a file, applying fallback extensions if necessary.

This function will try to find a file, first by attempting the given path itself, then by attempting the path with each extension from FileChecker::fallback_extensions. The first existing file (not directory), if any, will be returned.

§Arguments
  • path - The path to resolve.
  • uri - The original URI, used for error reporting.
§Returns

Returns Ok(PathBuf) with the resolved file path, or Err if no valid file is found. If Ok is returned, the contained PathBuf is guaranteed to exist and be a file.

Source

fn apply_index_files(&self, dir_path: &Path) -> Result<PathBuf>

Tries to find an index file in the given directory, returning the first match. The index file behavior is specified by FileChecker::index_files.

If this is non-None, index files must exist and resolved index files are required to be files, aside from the special name . - this will match the directory itself.

If None, index file resolution is disabled and this function simply returns the given path.

§Arguments
  • dir_path - The directory within which to search for index files. This is assumed to be an existing directory.
§Returns

Returns Ok(PathBuf) pointing to the first existing index file, or Err if no index file is found. If Ok is returned, the contained PathBuf is guaranteed to exist. In most cases, the returned path will be a file path.

If index files are disabled, simply returns Ok(dir_path).

Source

async fn check_file(&self, path: &Path, uri: &Uri) -> Status

Checks a resolved file, optionally verifying fragments for HTML files.

§Arguments
  • path - The resolved path to check.
  • uri - The original URI, used for error reporting.
§Returns

Returns a Status indicating the result of the check.

Source

async fn check_fragment(&self, path: &Path, uri: &Uri) -> Status

Checks for the existence of a fragment in a path.

The given path may be a file or a directory. A directory is treated as if it was an empty file with no fragments.

§Arguments
  • path - The path to the file or directory. Assumed to exist.
  • uri - The original URI, containing the fragment to check.
§Returns

Returns a Status indicating the result of the fragment check.

Trait Implementations§

Source§

impl Clone for FileChecker

Source§

fn clone(&self) -> FileChecker

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 FileChecker

Source§

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

Formats the value using the given formatter. Read more

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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