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/// Test utilities
77#[cfg(test)]
78#[macro_use]
79pub mod test_utils;
80
81#[cfg(test)]
82use doc_comment as _; // required for doctest
83use ring as _; // required for apple silicon
84
85#[cfg(feature = "native-tls")]
86use openssl_sys as _; // required for vendored-openssl feature
87
88#[doc(inline)]
89pub use crate::{
90 basic_auth::BasicAuthExtractor,
91 // Expose the `Handler` trait to allow defining external handlers (plugins)
92 chain::{ChainResult, Handler},
93 // Constants get exposed so that the CLI can use the same defaults as the library
94 client::{
95 Client, ClientBuilder, DEFAULT_MAX_REDIRECTS, DEFAULT_MAX_RETRIES,
96 DEFAULT_RETRY_WAIT_TIME_SECS, DEFAULT_TIMEOUT_SECS, DEFAULT_USER_AGENT, check,
97 },
98 collector::Collector,
99 filter::{Excludes, Filter, Includes},
100 types::{
101 AcceptRange, AcceptRangeError, Base, BasicAuthCredentials, BasicAuthSelector, CacheStatus,
102 CookieJar, ErrorKind, FileExtensions, FileType, Input, InputContent, InputSource, Request,
103 Response, ResponseBody, Result, Status, StatusCodeExcluder, StatusCodeSelector,
104 uri::valid::Uri,
105 },
106};