cassetter_core/lib.rs
1//! Language-agnostic core for cassetter.
2//!
3//! This crate holds the cassette format (YAML and TOML), request matching,
4//! security filtering, and body processing. It has no binding dependencies -
5//! `cassetter-python` (PyO3) and `cassetter-node` (napi-rs) are thin wrappers
6//! over these types, so every language binding shares one implementation and
7//! one definition of the cassette format.
8
9pub mod body;
10pub mod cassette;
11pub mod interop;
12pub mod matching;
13pub mod protocol;
14pub mod recording;
15pub mod security;
16
17use std::fmt;
18
19/// Errors produced by the core. Bindings map these onto their host language's
20/// native exception types.
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub enum CassetteError {
23 /// No cassette file exists at the given path.
24 NotFound(String),
25 /// Filesystem read/write failure.
26 Io(String),
27 /// A cassette could not be parsed or serialized.
28 Format(String),
29 /// A value was invalid: an unknown matcher, a bad body type, an
30 /// uncompilable scrub pattern, a malformed encoding.
31 Value(String),
32 /// An interaction index was out of range.
33 IndexOutOfRange(String),
34}
35
36impl fmt::Display for CassetteError {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 let msg = match self {
39 CassetteError::NotFound(m)
40 | CassetteError::Io(m)
41 | CassetteError::Format(m)
42 | CassetteError::Value(m)
43 | CassetteError::IndexOutOfRange(m) => m,
44 };
45 f.write_str(msg)
46 }
47}
48
49impl std::error::Error for CassetteError {}
50
51/// Convenience alias used throughout the core.
52pub type Result<T> = std::result::Result<T, CassetteError>;