1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! Structured error types for the scrapling core crate.
//!
//! All fallible operations in the library return [`Result<T>`], which is an
//! alias for `std::result::Result<T, Error>`. The [`Error`] enum has a variant
//! for each failure domain (parsing, selectors, encoding, etc.) and implements
//! automatic conversion from upstream error types via `#[from]`.
//!
//! # Storage errors
//!
//! The [`Error::Storage`] variant is only available when the `storage` Cargo
//! feature is enabled (it is on by default). When disabled, any code path
//! that would produce a storage error is statically removed.
use Error;
/// All errors produced by the scrapling core crate.
///
/// Each variant maps to a specific failure domain. Variants that wrap
/// upstream errors (e.g. [`regex::Error`], [`serde_json::Error`]) use
/// `#[from]` so the `?` operator converts them automatically.
///
/// # Examples
///
/// ```rust
/// use scrapling::Error;
///
/// fn example() -> scrapling::Result<()> {
/// let re = regex::Regex::new("[invalid")?; // auto-converts to Error::Regex
/// Ok(())
/// }
///
/// let err = example().unwrap_err();
/// assert!(matches!(err, Error::Regex(_)));
/// ```
/// Convenience alias used throughout the crate.
///
/// All public functions that can fail return `Result<T>` instead of
/// `std::result::Result<T, Error>` for brevity.
pub type Result<T> = Result;