nagios_range/lib.rs
1//! This crate provides simple types to parse and operate on a
2//! Nagios range as described in the [Nagios Development Guidelines](https://nagios-plugins.org/doc/guidelines.html#THRESHOLDFORMAT).
3//!
4//! The main type [NagiosRange] behaves similar to a [std::ops::RangeInclusive]
5//! but also provides methods that implement the extended behaviour of
6//! a Nagios range, i.e. checking if a value is inside or outside the
7//! range which is basically the same as the [std::ops::RangeInclusive::contains()]
8//! method but extends it with the inverse behaviour.
9//!
10//! # Examples
11//!
12//! Create a `NagiosRange` from a literal string.
13//! ```rust
14//! use nagios_range::{NagiosRange, Error};
15//!
16//! fn main() -> Result<(), Error> {
17//! let range = NagiosRange::from("@0:10");
18//! assert!(range.is_ok());
19//!
20//! Ok(())
21//! }
22//! ```
23//!
24//! Look if a `NagiosRange` checks for values inside
25//! or outside of its range.
26//! ```rust
27//! use nagios_range::{NagiosRange, Error};
28//!
29//! fn main() -> Result<(), Error> {
30//! // This is an "inside" range.
31//! let range = NagiosRange::from("@0:10")?;
32//! assert!(range.checks_inside());
33//! assert!(!range.checks_outside());
34//!
35//! Ok(())
36//! }
37//! ```
38//!
39//! Look if the start point of a `NagiosRange` (the lower bound)
40//! is negatively infinite.
41//! ```rust
42//! use nagios_range::{NagiosRange, Error};
43//!
44//! fn main() -> Result<(), Error> {
45//! let range = NagiosRange::from("@~:10")?;
46//! assert!(range.start_is_infinite());
47//!
48//! Ok(())
49//! }
50//! ```
51//!
52//! Probably the most important function when working with Nagios check plugins:
53//! Check if a value is "contained" by the range in respect to its [CheckType].
54//! ```rust
55//! use nagios_range::{NagiosRange, Error};
56//!
57//! fn main() -> Result<(), Error> {
58//! let range = NagiosRange::from("@~:10")?;
59//! assert!(range.check(5.0));
60//!
61//! let range = NagiosRange::from("20")?;
62//! assert!(range.check(30.0));
63//!
64//! Ok(())
65//! }
66//! ```
67pub mod error;
68pub mod types;
69pub use self::error::Error;
70pub use self::types::CheckType;
71pub use self::types::NagiosRange;