Struct Range

Source
pub struct Range {
    pub from: f64,
    pub till: f64,
}
Expand description

Closed interval [from, till]

§ru

Закрытый диапазон [from, till] - используется для представления ценового диапазона, и определяет несколько утилитарных методов: проверка на вхождение, выразить диапазон в процентах и тп.

Диапазон может быть:

  1. Возрастающий - конечное значение больше начального.
  2. Убывающий - конечное значение меньше начального.

§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

Source

pub fn new(from: f64, till: f64) -> Range

Create new range

§ru

Конструктор

§Examples
use avin_core::Range;

let r = Range::new(1000.0, 1500.0);
assert_eq!(r.from, 1000.0);
assert_eq!(r.till, 1500.0);
Source

pub fn min(&self) -> f64

Return min of range

§ru

Возвращает минимум диапазона.

§Examples
use avin_core::Range;

let r = Range::new(100.0, 101.5);
assert_eq!(r.min(), 100.0);

let r = Range::new(100.0, 99.1);
assert_eq!(r.min(), 99.1);
Source

pub fn max(&self) -> f64

Return max of range

§ru

Возвращает максимум диапазона.

§Examples
use avin_core::Range;

let r = Range::new(100.0, 101.5);
assert_eq!(r.max(), 101.5);

let r = Range::new(100.0, 99.1);
assert_eq!(r.max(), 100.0);
Source

pub fn mid(&self) -> f64

Returns the middle of the range

§ru

Возвращает середину диапазона.

§Examples
use avin_core::Range;

let r = Range::new(100.0, 105.0);
assert_eq!(r.mid(), 102.5);
Source

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);
Source

pub fn abs(&self) -> f64

Abs of range

§ru

Модуль диапазона

§Examples
use avin_core::Range;

let r = Range::new(1000.0, 1050.0);
assert_eq!(r.abs(), 50.0);

let r = Range::new(1050.0, 1000.0);
assert_eq!(r.abs(), 50.0);
Source

pub fn abs_n(&self) -> f64

Normalized abs of range

§ru

Нормализованный модуль диапазона

§Examples
use avin_core::Range;

let r = Range::new(900.0, 1000.0);
assert_eq!(r.abs_n(), 0.10);
Source

pub fn abs_p(&self) -> f64

Abs of range in percent

§ru

Модуль диапазона в процентах

§Examples
use avin_core::Range;

let r = Range::new(970.0, 1000.0);
assert_eq!(r.abs_p(), 3.0);
Source

pub fn delta(&self) -> f64

Delta of range (signed)

§ru

Дельта диапазона (знаковая)

§Examples
use avin_core::Range;

let r = Range::new(1000.0, 1050.0);
assert_eq!(r.delta(), 50.0);

let r = Range::new(1050.0, 1000.0);
assert_eq!(r.delta(), -50.0);
Source

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);
Source

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§

Source§

impl Debug for Range

Source§

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

Formats the value using the given formatter. Read more

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> 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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V