8000 Rollup of 6 pull requests by Dylan-DPC-zz · Pull Request #70800 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 6 pull requests #70800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 5, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add slice::fill
  • Loading branch information
yoshuawuyts committed Apr 4, 2020
commit edabceb4a3f0149323c381d5c75fe6957385addf
24 changes: 24 additions & 0 deletions src/libcore/slice/mod.rs
< 3FC9 td class="blob-num blob-num-expandable" colspan="2"> Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// * The `raw` and `bytes` submodules.
// * Boilerplate trait implementations.

use crate::borrow::Borrow;
use crate::cmp;
use crate::cmp::Ordering::{self, Equal, Greater, Less};
use crate::fmt;
Expand Down Expand Up @@ -2145,6 +2146,29 @@ impl<T> [T] {
}
}

/// Fills `self` with elements by cloning `value`.
///
/// # Examples
///
/// ```
/// #![feature(slice_fill)]
///
/// let mut buf = vec![0; 10];
/// buf.fill(1);
/// assert_eq!(buf, vec![1; 10]);
/// ```
#[unstable(feature = "slice_fill", issue = "70758")]
pub fn fill<V>(&mut self, value: V)
where
V: Borrow<T>,
T: Clone,
{
let value = value.borrow();
for el in self {
el.clone_from(value)
}
}

/// Copies the elements from `src` into `self`.
///
/// The length of `src` must be the same as `self`.
0