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
impl Interval
sourcepub fn start(&self) -> Option<Position>
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());
sourcepub fn end(&self) -> Option<Position>
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());
sourcepub fn contains(&self, position: Position) -> bool
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)?));
sourcepub fn intersects(&self, other: Self) -> bool
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 From<RangeInclusive<Position>> for Interval
impl From<RangeInclusive<Position>> for Interval
source§fn from(range: RangeInclusive<Position>) -> Self
fn from(range: RangeInclusive<Position>) -> Self
Converts to this type from the input type.
source§impl From<RangeToInclusive<Position>> for Interval
impl From<RangeToInclusive<Position>> for Interval
source§fn from(range: RangeToInclusive<Position>) -> Self
fn from(range: RangeToInclusive<Position>) -> Self
Converts to this type from the input type.
source§impl PartialEq for Interval
impl PartialEq for Interval
source§impl RangeBounds<Position> for Interval
impl RangeBounds<Position> for Interval
impl Copy for Interval
impl Eq for Interval
impl StructuralPartialEq for Interval
Auto Trait Implementations§
impl Freeze for Interval
impl RefUnwindSafe for Interval
impl Send for Interval
impl Sync for Interval
impl Unpin for Interval
impl UnwindSafe for Interval
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