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: boolWhether to check for the existence of fragments (e.g., #section-id) in HTML files.
fragment_checker: FragmentCheckerUtility for performing fragment checks in HTML files.
wikilink_resolver: Option<WikilinkResolver>Utility for optionally resolving Wikilinks.
Implementations§
Source§impl FileChecker
impl FileChecker
Sourcepub(crate) fn new(
base: Option<Base>,
fallback_extensions: Vec<String>,
index_files: Option<Vec<String>>,
include_fragments: bool,
include_wikilinks: bool,
) -> Result<Self>
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.
Sourcefn resolve_base(&self, path: &Path) -> PathBuf
fn resolve_base(&self, path: &Path) -> PathBuf
Sourcefn resolve_local_path<'a>(
&self,
path: &'a Path,
uri: &Uri,
) -> Result<Cow<'a, Path>>
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.
Sourcefn apply_fallback_extensions(&self, path: &Path, uri: &Uri) -> Result<PathBuf>
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.
Sourcefn apply_index_files(&self, dir_path: &Path) -> Result<PathBuf>
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).
Sourceasync fn check_file(&self, path: &Path, uri: &Uri) -> Status
async fn check_file(&self, path: &Path, uri: &Uri) -> Status
Sourceasync fn check_fragment(&self, path: &Path, uri: &Uri) -> Status
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
impl Clone for FileChecker
Source§fn clone(&self) -> FileChecker
fn clone(&self) -> FileChecker
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for FileChecker
impl !RefUnwindSafe for FileChecker
impl Send for FileChecker
impl Sync for FileChecker
impl Unpin for FileChecker
impl UnsafeUnpin for FileChecker
impl !UnwindSafe for FileChecker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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