about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorTyler Mandry <tmandry@gmail.com>2020-09-16 12:24:03 -0700
committerGitHub <noreply@github.com>2020-09-16 12:24:03 -0700
commit23a677787e4e36894fa8bd94c8d525f2a7d936f8 (patch)
tree0e8e3bc428d7638f5592cfcbb98f5b7fd2265c2a /library/alloc/src
parent7bb106fe633872de703af46381843057f8cd384f (diff)
parentf240abc1dc9e59bfabfb5ea765fa9eae0aad3122 (diff)
downloadrust-23a677787e4e36894fa8bd94c8d525f2a7d936f8.tar.gz
rust-23a677787e4e36894fa8bd94c8d525f2a7d936f8.zip
Rollup merge of #75026 - JulianKnodt:array_windows, r=Amanieu
Add array_windows fn

This mimicks the functionality added by array_chunks, and implements a const-generic form of
`windows`. It makes egregious use of `unsafe`, but by necessity because the array must be
re-interpreted as a slice of arrays, and unlike array_chunks this cannot be done by casting the
original array once, since each time the index is advanced it needs to move one element, not
`N`.

I'm planning on adding more tests, but this should be good enough as a premise for the functionality.
Notably: should there be more functions overwritten for the iterator implementation/in general?

~~I've marked the issue as #74985 as there is no corresponding exact issue for `array_windows`, but it's based of off `array_chunks`.~~

Edit: See Issue #75027 created by @lcnr for tracking issue

~~Do not merge until I add more tests, please.~~

r? @lcnr
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/lib.rs1
-rw-r--r--library/alloc/src/slice.rs2
2 files changed, 3 insertions, 0 deletions
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index 5774ebb9b19..7881c101f9f 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -76,6 +76,7 @@
 #![cfg_attr(test, feature(test))]
 #![feature(allocator_api)]
 #![feature(array_chunks)]
+#![feature(array_windows)]
 #![feature(allow_internal_unstable)]
 #![feature(arbitrary_self_types)]
 #![feature(box_patterns)]
diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs
index 55afdd94f44..79403cf8687 100644
--- a/library/alloc/src/slice.rs
+++ b/library/alloc/src/slice.rs
@@ -97,6 +97,8 @@ pub use core::slice::check_range;
 pub use core::slice::ArrayChunks;
 #[unstable(feature = "array_chunks", issue = "74985")]
 pub use core::slice::ArrayChunksMut;
+#[unstable(feature = "array_windows", issue = "75027")]
+pub use core::slice::ArrayWindows;
 #[stable(feature = "slice_get_slice", since = "1.28.0")]
 pub use core::slice::SliceIndex;
 #[stable(feature = "from_ref", since = "1.28.0")]