std.range.InclusiveRange
Valuetype pub copy InclusiveRangeAn inclusive range of integers.
Static methods
new
Show source codeHide source code
fn pub inline static new(start: Int, end: Int) -> InclusiveRange {
InclusiveRange(start: start, end: end)
}fn pub inline static new(start: Int, end: Int) -> InclusiveRangeReturns a new InclusiveRange over the given values.
Instance methods
!=
Show source codeHide source code
fn pub !=(other: ref Self) -> Bool {
!(self == other)
}fn pub !=(other: ref Self) -> BoolReturns true if self and the given object are not equal to each other.
==
Show source codeHide source code
fn pub inline ==(other: InclusiveRange) -> Bool {
@start == other.start and @end == other.end
}fn pub inline ==(other: InclusiveRange) -> BoolReturns true if self and other are identical.
Examples
Comparing two identical ranges:
1.to(10) == 1.to(10) # => true
Comparing two different ranges:
1.to(10) == 1.to(5) # => false
clone
Show source codeHide source code
fn pub inline clone -> InclusiveRange {
InclusiveRange(start: @start, end: @end)
}fn pub inline clone -> InclusiveRangeCreates a clone of self.
The returned value is an owned value that is the same type as the receiver
of this method. For example, cloning a ref Array[Int] results in a
Array[Int], not another ref Array[Int].
contains?
Show source codeHide source code
fn pub inline contains?(value: Int) -> Bool {
@start <= value and value <= @end
}fn pub inline contains?(value: Int) -> Boolend
Show source codeHide source code
fn pub inline end -> Int {
@end
}fn pub inline end -> IntReturns the last value in the range.
fmt
Show source codeHide source code
fn pub fmt(formatter: mut Formatter) {
formatter.write('[')
@start.fmt(formatter)
formatter.write(' to ')
@end.fmt(formatter)
formatter.write(']')
}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 inline inclusive? -> Bool {
true
}fn pub inline inclusive? -> BoolReturns true if the range is an inclusive range.
into_iter
Show source codeHide source code
fn pub move into_iter -> Stream[Int] {
iter
}fn pub move into_iter -> Stream[Int]Moves self into an iterator.
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 inline size -> Int {
if @end >= @start { @end - @start + 1 } else { 0 }
}fn pub inline size -> IntReturns the number of values in this range.
start
Show source codeHide source code
fn pub inline start -> Int {
@start
}fn pub inline start -> IntReturns the first value in the range.
Implemented traits
Clone
impl Clone for InclusiveRangeEqual
impl Equal for InclusiveRangeFormat
impl Format for InclusiveRangeHash
impl Hash for InclusiveRangeRange
impl Range for InclusiveRange