Add is_sorted unstable documentation
This commit is contained in:
parent
02477f6f99
commit
ce47dde59f
5 changed files with 41 additions and 3 deletions
11
src/doc/unstable-book/src/library-features/is-sorted.md
Normal file
11
src/doc/unstable-book/src/library-features/is-sorted.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# `is_sorted`
|
||||||
|
|
||||||
|
The tracking issue for this feature is: [#53485]
|
||||||
|
|
||||||
|
[#53485]: https://github.com/rust-lang/rust/issues/53485
|
||||||
|
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
Add the methods `is_sorted`, `is_sorted_by` and `is_sorted_by_key` to `[T]`;
|
||||||
|
add the methods `is_sorted`, `is_sorted_by` and `is_sorted_by_key` to
|
||||||
|
`Iterator`.
|
|
@ -2626,6 +2626,7 @@ pub trait Iterator {
|
||||||
/// assert!(std::iter::empty::<i32>().is_sorted());
|
/// assert!(std::iter::empty::<i32>().is_sorted());
|
||||||
/// assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted());
|
/// assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted());
|
||||||
/// ```
|
/// ```
|
||||||
|
#[inline]
|
||||||
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
||||||
fn is_sorted(self) -> bool
|
fn is_sorted(self) -> bool
|
||||||
where
|
where
|
||||||
|
@ -2676,6 +2677,7 @@ pub trait Iterator {
|
||||||
/// assert!(["c", "bb", "aaa"].iter().is_sorted_by_key(|s| s.len()));
|
/// assert!(["c", "bb", "aaa"].iter().is_sorted_by_key(|s| s.len()));
|
||||||
/// assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
|
/// assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
|
||||||
/// ```
|
/// ```
|
||||||
|
#[inline]
|
||||||
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
||||||
fn is_sorted_by_key<F, K>(self, mut f: F) -> bool
|
fn is_sorted_by_key<F, K>(self, mut f: F) -> bool
|
||||||
where
|
where
|
||||||
|
|
|
@ -2272,6 +2272,7 @@ impl<T> [T] {
|
||||||
/// assert!(empty.is_sorted());
|
/// assert!(empty.is_sorted());
|
||||||
/// assert!(![0.0, 1.0, std::f32::NAN].is_sorted());
|
/// assert!(![0.0, 1.0, std::f32::NAN].is_sorted());
|
||||||
/// ```
|
/// ```
|
||||||
|
#[inline]
|
||||||
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
||||||
pub fn is_sorted(&self) -> bool
|
pub fn is_sorted(&self) -> bool
|
||||||
where
|
where
|
||||||
|
@ -2319,6 +2320,7 @@ impl<T> [T] {
|
||||||
/// assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
|
/// assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
|
||||||
/// assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
|
/// assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
|
||||||
/// ```
|
/// ```
|
||||||
|
#[inline]
|
||||||
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
||||||
pub fn is_sorted_by_key<F, K>(&self, mut f: F) -> bool
|
pub fn is_sorted_by_key<F, K>(&self, mut f: F) -> bool
|
||||||
where
|
where
|
||||||
|
|
|
@ -9,8 +9,15 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// Assert `Iterator` methods are feature gated
|
||||||
assert!([1, 2, 2, 9].iter().is_sorted());
|
assert!([1, 2, 2, 9].iter().is_sorted());
|
||||||
//^ ERROR: use of unstable library feature 'is_sorted'
|
//^ ERROR: use of unstable library feature 'is_sorted'
|
||||||
assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
|
assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
|
||||||
//^ ERROR: use of unstable library feature 'is_sorted'
|
//^ ERROR: use of unstable library feature 'is_sorted'
|
||||||
|
|
||||||
|
// Assert `[T]` methods are feature gated
|
||||||
|
assert!([1, 2, 2, 9].is_sorted());
|
||||||
|
//^ ERROR: use of unstable library feature 'is_sorted'
|
||||||
|
assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
|
||||||
|
//^ ERROR: use of unstable library feature 'is_sorted'
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
|
error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
|
||||||
--> $DIR/feature-gate-is_sorted.rs:12:33
|
--> $DIR/feature-gate-is_sorted.rs:13:33
|
||||||
|
|
|
|
||||||
LL | assert!([1, 2, 2, 9].iter().is_sorted());
|
LL | assert!([1, 2, 2, 9].iter().is_sorted());
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
@ -7,13 +7,29 @@ LL | assert!([1, 2, 2, 9].iter().is_sorted());
|
||||||
= help: add #![feature(is_sorted)] to the crate attributes to enable
|
= help: add #![feature(is_sorted)] to the crate attributes to enable
|
||||||
|
|
||||||
error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
|
error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
|
||||||
--> $DIR/feature-gate-is_sorted.rs:14:39
|
--> $DIR/feature-gate-is_sorted.rs:15:39
|
||||||
|
|
|
|
||||||
LL | assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
|
LL | assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= help: add #![feature(is_sorted)] to the crate attributes to enable
|
= help: add #![feature(is_sorted)] to the crate attributes to enable
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
|
||||||
|
--> $DIR/feature-gate-is_sorted.rs:19:26
|
||||||
|
|
|
||||||
|
LL | assert!([1, 2, 2, 9].is_sorted());
|
||||||
|
| ^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: add #![feature(is_sorted)] to the crate attributes to enable
|
||||||
|
|
||||||
|
error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
|
||||||
|
--> $DIR/feature-gate-is_sorted.rs:21:32
|
||||||
|
|
|
||||||
|
LL | assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: add #![feature(is_sorted)] to the crate attributes to enable
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0658`.
|
For more information about this error, try `rustc --explain E0658`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue