Struct NagiosRange

Source
pub struct NagiosRange { /* private fields */ }
Expand description

A parsed Nagios range built from a literal string. A Nagios range works similar to std::ops::RangeInclusive in that it is bounded by the lower and upper bounds inclusively (start..=end). However it differs slightly in how it is used. It contains some logic to determine if an alert should be raised when it is compared to some value (either when inside or outside of the range).

Implementations§

Source§

impl NagiosRange

Source

pub fn from(input: &str) -> Result<Self, Error>

Creates a NagiosRange from a literal string.

use nagios_range::NagiosRange;

fn main() -> Result<(), nagios_range::Error> {
    let range = NagiosRange::from("@-10:10");
    assert!(range.is_ok());
    Ok(())
}
Source

pub fn new(check_type: CheckType, start: f64, end: f64) -> Result<Self, Error>

Creates a NagiosRange from a CheckType, lower and (inclusive) upper bounds.

use nagios_range::{NagiosRange, CheckType};

fn main() -> Result<(), nagios_range::Error> {
    let range = NagiosRange::new(CheckType::Inside, f64::NEG_INFINITY, 20.0);
    assert!(range.is_ok());
    assert_eq!(range?, NagiosRange::from("@~:20")?);
    Ok(())
}
Source

pub fn start(&self) -> &f64

Returns the lower bound of the range.

use nagios_range::NagiosRange;

fn main() -> Result<(), nagios_range::Error> {
    let range = NagiosRange::from("@-10:10")?;
    assert_eq!(range.start(), &-10.0);
    Ok(())
}
Source

pub fn end(&self) -> &f64

Returns the upper bound of the range.

use nagios_range::NagiosRange;

fn main() -> Result<(), nagios_range::Error> {
    let range = NagiosRange::from("@-10:10")?;
    assert_eq!(range.end(), &10.0);
    Ok(())
}
Source

pub fn start_is_infinite(&self) -> bool

Returns true if the lower bound is negative infinity. This is just a convenience method that calls f64::is_infinite() on start.

use nagios_range::NagiosRange;

fn main() -> Result<(), nagios_range::Error> {
    let range = NagiosRange::from("@~:10")?;
    assert!(range.start_is_infinite());
    assert_eq!(range.start_is_infinite(), range.start().is_infinite());
    Ok(())
}
Source

pub fn end_is_infinite(&self) -> bool

Returns true if the upper bound is positive infinity. This is just a convenience method that calls f64::is_infinite() on end.

use nagios_range::NagiosRange;

fn main() -> Result<(), nagios_range::Error> {
    let range = NagiosRange::from("@10:")?;
    assert!(range.end_is_infinite());
    assert_eq!(range.end_is_infinite(), range.end().is_infinite());
    Ok(())
}
Source

pub fn contains(&self, item: f64) -> bool

Returns true if item is contained in the range irregardless of the type of the NagiosRange. So this behaves just like std::ops::RangeInclusive::contains().

use nagios_range::NagiosRange;

fn main() -> Result<(), nagios_range::Error> {
    let range = NagiosRange::from("@~:10")?;
    assert!(range.contains(-50.0));
    assert!(range.contains(10.0));
    assert!(!range.contains(20.0));
    Ok(())
}
Source

pub fn check(&self, item: f64) -> bool

Returns true if a value is either inside or outside of the range depending on the type of Nagios range.

use nagios_range::NagiosRange;

fn main() -> Result<(), nagios_range::Error> {
    // When it is an "inside" range...
    let range = NagiosRange::from("@10:20")?;
    assert!(range.check(15.0));

    // ...inverted behaviour when it is an "outside" range...
    let range = NagiosRange::from("10:20")?;
    assert!(range.check(30.0));
    Ok(())
}
Source

pub fn checks_inside(&self) -> bool

Returns true if NagiosRange::check() checks if a value lies inside the range (start <= item <= end).

use nagios_range::NagiosRange;

fn main() -> Result<(), nagios_range::Error> {
    let range = NagiosRange::from("@~:10")?;
    assert!(range.checks_inside());
    Ok(())
}
Source

pub fn checks_outside(&self) -> bool

Returns true if NagiosRange::check() checks if a value lies outside the range (start > item > end).

use nagios_range::NagiosRange;

fn main() -> Result<(), nagios_range::Error> {
    let range = NagiosRange::from("10:50")?;
    assert!(range.checks_outside());
    Ok(())
}
Source

pub fn into_inner(self) -> (CheckType, f64, f64)

Destructures the NagiosRange into a CheckType and the lower and (inclusive) upper bounds.

use nagios_range::{NagiosRange, CheckType};

fn main() -> Result<(), nagios_range::Error> {
    let range = NagiosRange::from("10:50")?;
    let (check_type, start, end) = range.into_inner();
    assert_eq!(check_type, CheckType::Outside);
    assert_eq!(start, 10.0);

    let new_range = NagiosRange::new(check_type, start, end);
    assert!(new_range.is_ok());
    Ok(())
}

Trait Implementations§

Source§

impl Clone for NagiosRange

Source§

fn clone(&self) -> NagiosRange

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NagiosRange

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for NagiosRange

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for NagiosRange

Source§

fn eq(&self, other: &NagiosRange) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for NagiosRange

Source§

impl StructuralPartialEq for NagiosRange

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.