本文簡要介紹rust語言中 Struct core::ops::Range 的用法。
用法
pub struct Range<Idx> {
    pub start: Idx,
    pub end: Idx,
}一個(半開的)範圍,包含在下麵和專門在上麵(start..end)。
範圍 start..end 包含所有帶有 start <= x < end 的值。如果 start >= end 則為空。
例子
start..end 語法是 Range :
assert_eq!((3..5), std::ops::Range { start: 3, end: 5 });
assert_eq!(3 + 4 + 5, (3..6).sum());let arr = [0, 1, 2, 3, 4];
assert_eq!(arr[ ..  ], [0, 1, 2, 3, 4]);
assert_eq!(arr[ .. 3], [0, 1, 2      ]);
assert_eq!(arr[ ..=3], [0, 1, 2, 3   ]);
assert_eq!(arr[1..  ], [   1, 2, 3, 4]);
assert_eq!(arr[1.. 3], [   1, 2      ]); // This is a `Range`
assert_eq!(arr[1..=3], [   1, 2, 3   ]);字段
start: Idx範圍的下限(包括)。
end: Idx範圍的上限(不包括)。
相關用法
- Rust Range.is_empty用法及代碼示例
- Rust RangeTo用法及代碼示例
- Rust RangeInclusive.start用法及代碼示例
- Rust RangeBounds.contains用法及代碼示例
- Rust RangeInclusive.contains用法及代碼示例
- Rust RangeFrom.contains用法及代碼示例
- Rust RangeFull用法及代碼示例
- Rust RangeBounds.end_bound用法及代碼示例
- Rust RangeInclusive.into_inner用法及代碼示例
- Rust RangeToInclusive用法及代碼示例
- Rust RangeToInclusive.contains用法及代碼示例
- Rust RangeTo.contains用法及代碼示例
- Rust RangeInclusive.end用法及代碼示例
- Rust RangeInclusive.new用法及代碼示例
- Rust RangeFrom用法及代碼示例
- Rust Range.contains用法及代碼示例
- Rust RangeInclusive用法及代碼示例
- Rust RangeInclusive.is_empty用法及代碼示例
- Rust RangeBounds.start_bound用法及代碼示例
- Rust RandomState.new用法及代碼示例
- Rust RandomState用法及代碼示例
- Rust RawEntryMut.and_modify用法及代碼示例
- Rust RawEntryMut.or_insert_with用法及代碼示例
- Rust RawEntryMut.or_insert用法及代碼示例
- Rust Result.unwrap_or_else用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 Struct core::ops::Range。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
