Expand description

lychee-lib is the library component of lychee, and is used for checking links.

“Hello world” example:

use lychee_lib::Result;

#[tokio::main]
async fn main() -> Result<()> {
  let response = lychee_lib::check("https://github.com/lycheeverse/lychee").await?;
  println!("{response}");
  Ok(())
}

For more specific use-cases you can build a lychee client yourself, using the ClientBuilder which can be used to configure and run your own link checker and grants full flexibility:

use lychee_lib::{ClientBuilder, Result, Status};

#[tokio::main]
async fn main() -> Result<()> {
  let client = ClientBuilder::default().client()?;
  let response = client.check("https://github.com/lycheeverse/lychee").await?;
  assert!(response.status().is_success());
  Ok(())
}

Modules

A pool of clients, to handle concurrent checks

Functionality to extract URIs from inputs

Filters are a way to define behavior when encountering URIs that need to be treated differently, such as local IPs or e-mail addresses

Remapping rules which allow to map URIs matching a pattern to a different URI. Use in moderation as there are no safety- or performance guarantees.

Structs

Handles incoming requests and returns responses.

Builder for Client.

Collector keeps the state of link collection It drives the link extraction from inputs

Exclude configuration for the link checker. You can ignore links based on regex patterns.

A generic URI filter Used to decide if a given URI should be checked or skipped

Include configuration for the link checker. You can include links based on regex patterns

Lychee Input with optional file hint for parsing

Encapsulates the content for a given input

A request type that can be handle by lychee

Response type returned by lychee after checking a URI

Encapsulates the state of a URI check

Lychee’s own representation of a URI, which encapsulates all supported formats.

Enums

When encountering links without a full domain in a document, the base determines where this resource can be found. Both, local and remote targets are supported.

Representation of the status of a cached request. This is kept simple on purpose because the type gets serialized to a cache file and might need to be parsed by other tools or edited by humans.

Kinds of status errors Note: The error messages can change over time, so don’t match on the output

FileType defines which file types lychee can handle

Input types which lychee supports

Response status of the request.

Constants

Default number of redirects before a request is deemed as failed, 5.

Default number of retries before a request is deemed as failed, 3.

Default wait time in seconds between requests, 1.

Default timeout in seconds before a request is deemed as failed, 20.

Default user agent, lychee-<PKG_VERSION>.

Functions

A convenience function to check a single URI.

Type Definitions

The lychee Result type