pub struct Range {
pub from: f64,
pub till: f64,
}Expand description
Closed interval [from, till]
§ru
Закрытый диапазон [from, till] - используется для представления ценового диапазона, и определяет несколько утилитарных методов: проверка на вхождение, выразить диапазон в процентах и тп.
Диапазон может быть:
- Возрастающий - конечное значение больше начального.
- Убывающий - конечное значение меньше начального.
§Examples
use avin_core::Range;
let r = Range::new(1000.0, 1500.0);
assert_eq!(r.delta(), 500.0);
let r = Range::new(1500.0, 1000.0);
assert_eq!(r.delta(), -500.0);Fields§
§from: f64Начало диапазона (включительно)
till: f64Конец диапазона (включительно)
Implementations§
Source§impl Range
impl Range
Sourcepub fn contains(&self, value: f64) -> bool
pub fn contains(&self, value: f64) -> bool
Check for value in range.
§ru
Проверка на вхождения в диапазон.
§Examples
use avin_core::Range;
let r = Range::new(100.0, 105.0);
assert_eq!(r.contains(103.0), true);
assert_eq!(r.contains(100.0), true);
assert_eq!(r.contains(105.0), true);
assert_eq!(r.contains(105.1), false);
assert_eq!(r.contains(99.9), false);Sourcepub fn delta_n(&self) -> f64
pub fn delta_n(&self) -> f64
Normalized delta of range (signed)
§ru
Нормализованная дельта диапазона (знаковая) - показывает коэффициент изменения конечной цены относительно начальной.
§Examples
use avin_core::Range;
let r = Range::new(1000.0, 1050.0);
assert_eq!(r.delta_n(), 0.05);
let r = Range::new(1000.0, 900.0);
assert_eq!(r.delta_n(), -0.10);Sourcepub fn delta_p(&self) -> f64
pub fn delta_p(&self) -> f64
Delta of range in percent
§ru
Дельта диапазона (знаковая) в процентах - показывает процент изменения конечной цены относительно начальной.
§Examples
use avin_core::Range;
let r = Range::new(1000.0, 1050.0);
assert_eq!(r.delta_p(), 5.0);
let r = Range::new(1000.0, 900.0);
assert_eq!(r.delta_p(), -10.0);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Range
impl RefUnwindSafe for Range
impl Send for Range
impl Sync for Range
impl Unpin for Range
impl UnwindSafe for Range
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more