[−][src]Struct temporal_networks::interval::Interval
An interval represents a context-agnostic inclusive [lower, upper] time range. While Interval may be accessible from JS, the Rust implementation includes additional operator overloads for simplified arithmetic.
JS-specific
- Use
.toJSON()
if you want to convert anInterval
to an array of numbers - Using indexing to get the lower and upper bounds is also an option, eg.
interval[0] === lower && interval[1] === upper
- use
Number.MAX_VALUE
and-Number.MAX_VALUE
to represent infinity and -infinity respectively
Examples
Interval arithmetic in Rust.
use temporal_networks::interval::Interval; let interval1 = Interval::new(0., 10.); let interval2 = Interval::new(5., 16.); let summed_interval = Interval::new(5., 26.); assert_eq!(interval1 + interval2, summed_interval); let diff_interval = Interval::new(-5., 16.); assert_eq!(interval2 - interval1, diff_interval); let unioned_interval = Interval::new(5., 10.); assert_eq!(interval1 & interval2, unioned_interval);
Methods
impl Interval
[src]
pub fn new(lower: f64, upper: f64) -> Interval
[src]
Create a new Interval
pub fn from_vec(other: Vec<f64>) -> Interval
[src]
Get an interval from a vector
pub fn to_json(&self) -> JsValue
[src]
Convert the interval to JSON [lower, upper]
pub fn lower(&self) -> f64
[src]
The lower bound of the range
pub fn upper(&self) -> f64
[src]
The upper bound of the range
pub fn contains(&self, v: f64) -> bool
[src]
Whether or not a point in time falls within a range
pub fn is_valid(&self) -> bool
[src]
A check that ensures the lower bound is less than the upper bound
pub fn converged(&self) -> bool
[src]
Whether or not the interval has converged to a time
pub fn union(&self, other: &Interval) -> Interval
[src]
Union these intervals
Trait Implementations
impl Add<Interval> for Interval
[src]
type Output = Interval
The resulting type after applying the +
operator.
fn add(self, other: Interval) -> Interval
[src]
create a new interval from the addition of two other intervals
impl AddAssign<Interval> for Interval
[src]
fn add_assign(&mut self, other: Interval)
[src]
impl BitAnd<Interval> for Interval
[src]
type Output = Interval
The resulting type after applying the &
operator.
fn bitand(self, other: Interval) -> Interval
[src]
impl BitAndAssign<Interval> for Interval
[src]
fn bitand_assign(&mut self, other: Interval)
[src]
impl Clone for Interval
[src]
impl Copy for Interval
[src]
impl Debug for Interval
[src]
impl Default for Interval
[src]
impl<'de> Deserialize<'de> for Interval
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Display for Interval
[src]
impl From<Interval> for JsValue
[src]
impl FromWasmAbi for Interval
[src]
type Abi = u32
The wasm ABI type that this converts from when coming back out from the ABI boundary. Read more
unsafe fn from_abi(js: u32) -> Self
[src]
impl IntoWasmAbi for Interval
[src]
type Abi = u32
The wasm ABI type that this converts into when crossing the ABI boundary. Read more
fn into_abi(self) -> u32
[src]
impl Neg for Interval
[src]
type Output = Interval
The resulting type after applying the -
operator.
fn neg(self) -> Interval
[src]
impl OptionFromWasmAbi for Interval
[src]
impl OptionIntoWasmAbi for Interval
[src]
impl PartialEq<Interval> for Interval
[src]
impl RefFromWasmAbi for Interval
[src]
type Abi = u32
The wasm ABI type references to Self
are recovered from.
type Anchor = Ref<'static, Interval>
The type that holds the reference to Self
for the duration of the invocation of the function that has an &Self
parameter. This is required to ensure that the lifetimes don't persist beyond one function call, and so that they remain anonymous. Read more
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor
[src]
impl RefMutFromWasmAbi for Interval
[src]
type Abi = u32
Same as RefFromWasmAbi::Abi
type Anchor = RefMut<'static, Interval>
Same as RefFromWasmAbi::Anchor
unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
[src]
impl Serialize for Interval
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl StructuralPartialEq for Interval
[src]
impl Sub<Interval> for Interval
[src]
type Output = Interval
The resulting type after applying the -
operator.
fn sub(self, other: Interval) -> Interval
[src]
impl SubAssign<Interval> for Interval
[src]
fn sub_assign(&mut self, other: Interval)
[src]
impl WasmDescribe for Interval
[src]
Auto Trait Implementations
impl RefUnwindSafe for Interval
impl Send for Interval
impl Sync for Interval
impl Unpin for Interval
impl UnwindSafe for Interval
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ReturnWasmAbi for T where
T: IntoWasmAbi,
[src]
T: IntoWasmAbi,
type Abi = <T as IntoWasmAbi>::Abi
Same as IntoWasmAbi::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,