Skip to main content

lychee_lib/
lib.rs

1//! `lychee-lib` is the library component of [`lychee`], and is used for checking links.
2//!
3//! "Hello world" example:
4//!
5//! ```
6//! use lychee_lib::Result;
7//!
8//! #[tokio::main]
9//! async fn main() -> Result<()> {
10//!   let response = lychee_lib::check("https://github.com/lycheeverse/lychee").await?;
11//!   println!("{response}");
12//!   Ok(())
13//! }
14//! ```
15//!
16//! For more specific use-cases you can build a lychee client yourself,
17//! using the [`ClientBuilder`] which can be used to
18//! configure and run your own link checker and grants full flexibility:
19//!
20//! ```
21//! use lychee_lib::{ClientBuilder, Result, Status};
22//!
23//! #[tokio::main]
24//! async fn main() -> Result<()> {
25//!   let client = ClientBuilder::default().client()?;
26//!   let response = client.check("https://github.com/lycheeverse/lychee").await?;
27//!   assert!(response.status().is_success());
28//!   Ok(())
29//! }
30//! ```
31//!
32//! [`lychee`]: https://github.com/lycheeverse/lychee
33#![warn(clippy::all, clippy::pedantic)]
34#![warn(
35    absolute_paths_not_starting_with_crate,
36    rustdoc::invalid_html_tags,
37    missing_copy_implementations,
38    missing_debug_implementations,
39    semicolon_in_expressions_from_macros,
40    unreachable_pub,
41    unused_crate_dependencies,
42    unused_extern_crates,
43    variant_size_differences,
44    clippy::missing_const_for_fn
45)]
46#![deny(anonymous_parameters, macro_use_extern_crate)]
47#![deny(missing_docs)]
48#![allow(clippy::module_name_repetitions)]
49
50#[cfg(doctest)]
51doc_comment::doctest!("../../README.md");
52
53#[cfg(all(test, not(doctest)))]
54use tokio_stream as _;
55
56/// Check online archives to try and restore broken links
57pub mod archive;
58mod basic_auth;
59pub mod chain;
60mod checker;
61mod client;
62/// A pool of clients, to handle concurrent checks
63pub mod collector;
64mod quirks;
65mod retry;
66mod types;
67mod utils;
68
69/// Functionality to extract URIs from inputs
70pub mod extract;
71
72pub mod remap;
73
74/// Per-host rate limiting and concurrency control
75pub mod ratelimit;
76
77/// Filters are a way to define behavior when encountering
78/// URIs that need to be treated differently, such as
79/// local IPs or e-mail addresses
80pub mod filter;
81
82pub mod cache;
83
84pub mod waiter;
85
86#[cfg(test)]
87use doc_comment as _; // required for doctest
88use ring as _; // required for apple silicon
89
90#[doc(inline)]
91pub use crate::{
92    basic_auth::BasicAuthExtractor,
93    // Expose the `Handler` trait to allow defining external handlers (plugins)
94    chain::{ChainResult, Handler},
95    // Constants get exposed so that the CLI can use the same defaults as the library
96    client::{
97        Client, ClientBuilder, DEFAULT_MAX_REDIRECTS, DEFAULT_MAX_RETRIES,
98        DEFAULT_RETRY_WAIT_TIME_SECS, DEFAULT_TIMEOUT_SECS, DEFAULT_USER_AGENT, check,
99    },
100    collector::Collector,
101    filter::{Excludes, Filter, Includes},
102    types::{
103        BaseInfo, BasicAuthCredentials, BasicAuthSelector, CacheStatus, CookieJar, ErrorKind,
104        FileExtensions, FileType, Input, InputContent, InputResolver, InputSource, LycheeResult,
105        Preprocessor, Redirect, Redirects, Request, RequestError, ResolvedInputSource, Response,
106        ResponseBody, Result, Status, StatusCodeSelector, StatusRange, StatusRangeError,
107        uri::raw::RawUri, uri::raw::RawUriSpan, uri::valid::Uri,
108    },
109};