std.range.ExclusiveRange
class pub ExclusiveRange
An exclusive range of integers.
Fields
start
let pub @start: Int
The start value of the range.
end
let pub @end: Int
The end value of the range.
Static methods
new
Show source codeHide source code
fn pub static new(start: Int, end: Int) -> ExclusiveRange {
ExclusiveRange(start: start, end: end)
}
fn pub static new(start: Int, end: Int) -> ExclusiveRange
Returns a new ExclusiveRange
over the given values.
Instance methods
!=
Show source codeHide source code
fn pub !=(other: T) -> Bool {
(self == other).false?
}
fn pub !=(other: T) -> Bool
Returns true
if self
and the given object are not equal to each other.
==
Show source codeHide source code
fn pub ==(other: ref ExclusiveRange) -> Bool {
@start == other.start and @end == other.end
}
fn pub ==(other: ref ExclusiveRange) -> Bool
Returns true
if self
and other
are identical.
Examples
Comparing two identical ranges:
1.until(10) == 1.until(10) # => true
Comparing two different ranges:
1.until(10) == 1.until(5) # => false
clone
Show source codeHide source code
fn pub clone -> ExclusiveRange {
ExclusiveRange(start: @start, end: @end)
}
fn pub clone -> ExclusiveRange
Creates a clone of self
.
contains?
Show source codeHide source code
fn pub contains?(value: ref Int) -> Bool {
@start <= value and value < @end
}
fn pub contains?(value: ref Int) -> Bool
Returns true
if the given argument resides in the range of self
.
Examples
Checking if a Range
covers a value:
1.until(10).cover?(5) # => true
1.until(10).cover?(15) # => false
end
Show source codeHide source code
fn pub end -> Int {
@end
}
fn pub end -> Int
Returns the last value in the range.
fmt
Show source codeHide source code
fn pub fmt(formatter: mut Formatter) {
@start.fmt(formatter)
formatter.write(' until ')
@end.fmt(formatter)
}
fn pub fmt(formatter: mut Formatter)
Formats self
in a human-readable format for debugging purposes.
hash
Show source codeHide source code
fn pub hash[H: mut + Hasher](hasher: mut H) {
@start.hash(hasher)
@end.hash(hasher)
}
fn pub hash[H: mut + Hasher](hasher: mut H: mut)
Writes the hash for self
into the given Hasher
.
inclusive?
Show source codeHide source code
fn pub inclusive? -> Bool {
false
}
fn pub inclusive? -> Bool
Returns true
if the range is an inclusive range.
iter
Show source codeHide source code
fn pub iter -> Stream[Int] {
let mut current = @start
let end = @end
Stream.new(fn move {
if current < end {
Option.Some(current := current + 1)
} else {
Option.None
}
})
}
fn pub iter -> Stream[Int]
Returns an iterator over the values in self
.
size
Show source codeHide source code
fn pub size -> Int {
if @end >= @start { @end - @start } else { 0 }
}
fn pub size -> Int
Returns the number of values in this range.
start
Show source codeHide source code
fn pub start -> Int {
@start
}
fn pub start -> Int
Returns the first value in the range.
Implemented traits
Clone
impl Clone[ExclusiveRange] for ExclusiveRange
Contains
impl Contains[Int] for ExclusiveRange
Equal
impl Equal[ref ExclusiveRange] for ExclusiveRange
Format
impl Format for ExclusiveRange
Hash
impl Hash for ExclusiveRange
Range
impl Range for ExclusiveRange