Struct noodles_core::region::interval::Interval

source ·
pub struct Interval { /* private fields */ }
Expand description

An interval.

An interval can be closed ([a, b]), left-closed and right-unbounded ([a, ∞)), left-unbounded and right-closed ((-∞, b]), or unbounded ((-∞, ∞)).

Implementations§

source§

impl Interval

source

pub fn start(&self) -> Option<Position>

Returns the start.

§Examples
use noodles_core::{region::Interval, Position};

let start = Position::try_from(8)?;
let end = Position::try_from(13)?;
let a = Interval::from(start..=end);
assert_eq!(a.start(), Some(start));

let b = Interval::from(..=end);
assert!(b.start().is_none());
source

pub fn end(&self) -> Option<Position>

Returns the end.

§Examples
use noodles_core::{region::Interval, Position};

let start = Position::try_from(8)?;
let end = Position::try_from(13)?;
let a = Interval::from(start..=end);
assert_eq!(a.end(), Some(end));

let b = Interval::from(start..);
assert!(b.end().is_none());
source

pub fn contains(&self, position: Position) -> bool

Returns whether the given position is in this interval.

§Examples
use noodles_core::{region::Interval, Position};

let interval = Interval::from(Position::try_from(5)?..=Position::try_from(13)?);
assert!(interval.contains(Position::try_from(8)?));
assert!(!interval.contains(Position::try_from(2)?));
assert!(!interval.contains(Position::try_from(21)?));
source

pub fn intersects(&self, other: Self) -> bool

Returns whether the given interval intersects this interval.

§Examples
use noodles_core::{region::Interval, Position};

let a = Interval::from(Position::try_from(5)?..=Position::try_from(13)?);
let b = Interval::from(Position::try_from(8)?..=Position::try_from(21)?);
assert!(a.intersects(b));

let c = Interval::from(Position::try_from(2)?..=Position::try_from(3)?);
assert!(!a.intersects(c));

Trait Implementations§

source§

impl Clone for Interval

source§

fn clone(&self) -> Interval

Returns a copy 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 Interval

source§

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

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

impl Display for Interval

source§

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

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

impl From<RangeFrom<Position>> for Interval

source§

fn from(range: RangeFrom<Position>) -> Self

Converts to this type from the input type.
source§

impl From<RangeFull> for Interval

source§

fn from(_: RangeFull) -> Self

Converts to this type from the input type.
source§

impl From<RangeInclusive<Position>> for Interval

source§

fn from(range: RangeInclusive<Position>) -> Self

Converts to this type from the input type.
source§

impl From<RangeToInclusive<Position>> for Interval

source§

fn from(range: RangeToInclusive<Position>) -> Self

Converts to this type from the input type.
source§

impl FromStr for Interval

§

type Err = ParseError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq for Interval

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl RangeBounds<Position> for Interval

source§

fn start_bound(&self) -> Bound<&Position>

Start index bound. Read more
source§

fn end_bound(&self) -> Bound<&Position>

End index bound. Read more
1.35.0 · source§

fn contains<U>(&self, item: &U) -> bool
where T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
source§

impl Copy for Interval

source§

impl Eq for Interval

source§

impl StructuralPartialEq for Interval

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> 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,

§

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§

default 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>,

§

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>,

§

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.