git_checks_config/lib.rs
1// Copyright Kitware, Inc.
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9// XXX(rust-1.66)
10#![allow(clippy::uninlined_format_args)]
11
12//! Configurations for Git checks
13//!
14//! When using git checks, it is often useful to store what checks to read within
15//! configuration files. This crate allows for checks to also offer support for reading
16//! structures from configuration files and turning them into instances of checks. Another point
17//! is that adding another check to a crate requires consumers to update to consume that new check.
18//! Here, the [`inventory`][inventory] is used to create a global registry that consuming
19//! applications can use to automatically discover new checks added to the application from
20//! anywhere.
21//!
22//!## Caveats
23//!
24//! One downside of this is that there is then one "blessed" serialization for a check.
25//! This crate aims to not preclude such uses and as such, checks themselves should generally
26//! not implement `Deserialize`. Instead, a separate structure should be created which then
27//! creates the check.
28//!
29//! ## Example
30//!
31//! ```rust,ignore
32//! struct MyCheck {
33//! field1: bool,
34//! }
35//!
36//! impl Check for MyCheck {
37//! // implementation
38//! }
39//!
40//! struct MyCheckConfig {
41//! #[serde(default)]
42//! field1: bool
43//! }
44//!
45//! impl IntoCheck for MyCheckConfig {
46//! type Check = MyCheck;
47//!
48//! fn into_check(self) -> Self::Check {
49//! MyCheck {
50//! field1: self.field1,
51//! }
52//! }
53//! }
54//!
55//! register_checks! {
56//! MyCheckConfig {
57//! "name_of_check" => CommitCheckConfig,
58//! },
59//! }
60//! ```
61
62mod registry;
63pub use registry::*;
64
65#[macro_use]
66mod macros;
67
68#[cfg(test)]
69mod test;
70
71/// Re-export to guarantee finding the registered instances.
72pub use inventory;