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/// Check online archives to try and restore broken links
54pub mod archive;
55mod basic_auth;
56pub mod chain;
57mod checker;
58mod client;
59/// A pool of clients, to handle concurrent checks
60pub mod collector;
61mod quirks;
62mod retry;
63mod types;
64mod utils;
65
66/// Functionality to extract URIs from inputs
67pub mod extract;
68
69pub mod remap;
70
71/// Filters are a way to define behavior when encountering
72/// URIs that need to be treated differently, such as
73/// local IPs or e-mail addresses
74pub mod filter;
75
76#[cfg(test)]
77use doc_comment as _; // required for doctest
78use ring as _; // required for apple silicon
79
80#[cfg(feature = "native-tls")]
81use openssl_sys as _; // required for vendored-openssl feature
82
83#[doc(inline)]
84pub use crate::{
85 basic_auth::BasicAuthExtractor,
86 // Expose the `Handler` trait to allow defining external handlers (plugins)
87 chain::{ChainResult, Handler},
88 // Constants get exposed so that the CLI can use the same defaults as the library
89 client::{
90 Client, ClientBuilder, DEFAULT_MAX_REDIRECTS, DEFAULT_MAX_RETRIES,
91 DEFAULT_RETRY_WAIT_TIME_SECS, DEFAULT_TIMEOUT_SECS, DEFAULT_USER_AGENT, check,
92 },
93 collector::Collector,
94 filter::{Excludes, Filter, Includes},
95 types::{
96 AcceptRange, AcceptRangeError, Base, BasicAuthCredentials, BasicAuthSelector, CacheStatus,
97 CookieJar, ErrorKind, FileExtensions, FileType, Input, InputContent, InputResolver,
98 InputSource, Redirects, Request, ResolvedInputSource, Response, ResponseBody, Result,
99 Status, StatusCodeExcluder, StatusCodeSelector, uri::valid::Uri,
100 },
101};