1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! `Slice::fill` prototype.
//!
//! C++ ships with
//! [`std::fill`](https://en.cppreference.com/w/cpp/algorithm/fill) which fills a
//! range of memory with a given byte. Rust currently doesn't have a standard
//! library equivalent for that.
//!
//! [Issue 2067](https://github.com/rust-lang/rfcs/issues/2067) on the RFCs
//! repo proposes a safe wrapper around `memset(3)` call. This is a reference
//! implementation of the API proposed in the issue that optimizes to `memset`
//! in many cases but leaves the exact performance profile undisclosed.
//!
//! As Rust makes progress on specialization this can later be lifted to
//! guarantee the fastest known implementation is used for any specific type.
//! But until then it provides a convenient API to fill slices of memory with
//! repeating patterns, which will generally be optimized to be very fast
//! already.
//!
//! # Examples
//!
//! ```
//! use slice_fill::SliceExt;
//!
//! let mut buf = vec![0; 10];
//! buf.fill(1);
//! assert_eq!(buf, vec![1; 10]);
//! ```
//!
//! # Further reading
//! - [The hunt for the fastest zero](https://travisdowns.github.io/blog/2020/01/20/zero.html)
//! - [Filling large arrays with zeroes quickly in C](https://lemire.me/blog/2020/01/20/filling-large-arrays-with-zeroes-quickly-in-c/)
//! - [Godbolt ASM output](https://godbolt.org/z/ikyFAo)
/// Extension trait for `std::slice`.