#![ cfg_attr( not( feature = "use_std" ), no_std ) ]
#![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ]
#![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ]
#![ doc( html_root_url = "https://docs.rs/winterval/latest/winterval/" ) ]
#![ warn( rust_2018_idioms ) ]
#![ warn( missing_debug_implementations ) ]
#![ warn( missing_docs ) ]
#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ]
#[ cfg( feature = "use_std" ) ]
pub( crate ) mod private
{
pub trait IntervalAdapter< T = isize >
where
T : std::ops::Sub< Output = T > + std::ops::Add< Output = T > + Copy,
isize : Into< T >,
{
fn first( &self ) -> T;
fn last( &self ) -> T;
fn len( &self ) -> T
{
let one : T = 1.into();
self.last() - self.first() + one
}
fn closed( &self ) -> ( T, T )
{
( self.first(), self.last() )
}
fn closed_open( &self ) -> ( T, T )
{
let one : T = 1.into();
( self.first(), self.last() + one )
}
fn first_len( &self ) -> ( T, T )
{
( self.first(), self.len() )
}
}
#[ derive( PartialEq, Debug ) ]
pub struct Interval< T = isize >
where
T : std::ops::Sub< Output = T > + std::ops::Add< Output = T > + Copy,
isize : Into< T >,
{
_first : T,
_last : T,
}
impl< T > Interval< T >
where
T : std::ops::Sub< Output = T > + std::ops::Add< Output = T > + Copy,
isize : Into< T >,
{
pub fn new( first : T, last : T ) -> Self
{
Self { _first : first, _last : last }
}
}
impl< T > IntervalAdapter< T >
for Interval< T >
where
T : std::ops::Sub< Output = T > + std::ops::Add< Output = T > + Copy,
isize : Into< T >,
{
fn first( &self ) -> T
{
self._first
}
fn last( &self ) -> T
{
self._last
}
}
impl< T > IntervalAdapter< T >
for ::core::ops::Range< T >
where
T : std::ops::Sub< Output = T > + std::ops::Add< Output = T > + Copy,
isize : Into< T >,
{
fn first( &self ) -> T
{
self.start
}
fn last( &self ) -> T
{
let one : T = 1.into();
self.end - one
}
}
impl< T > IntervalAdapter< T >
for ::core::ops::RangeInclusive< T >
where
T : std::ops::Sub< Output = T > + std::ops::Add< Output = T > + Copy,
isize : Into< T >,
{
fn first( &self ) -> T
{
*self.start()
}
fn last( &self ) -> T
{
*self.end()
}
}
impl< T > From< ::core::ops::Range< T > >
for Interval< T >
where
T : std::ops::Sub< Output = T > + std::ops::Add< Output = T > + Copy,
isize : Into< T >,
{
fn from( src : ::core::ops::Range< T > ) -> Self
{
let one : T = 1.into();
Self { _first : src.start, _last : src.end - one }
}
}
impl< T > From< ::core::ops::RangeInclusive< T > >
for Interval< T >
where
T : std::ops::Sub< Output = T > + std::ops::Add< Output = T > + Copy,
isize : Into< T >,
{
fn from( src : ::core::ops::RangeInclusive< T > ) -> Self
{
Self { _first : *src.start(), _last : *src.end() }
}
}
}
pub mod protected
{
pub use super::orphan::*;
}
pub use protected::*;
pub mod orphan
{
pub use super::exposed::*;
}
pub mod exposed
{
pub use super::prelude::*;
#[ cfg( feature = "use_std" ) ]
pub use super::private::
{
IntervalAdapter,
Interval,
};
}
pub use exposed::*;
pub mod prelude
{
}