This report is the collaborative effort of @matthewjasper and @Centril.
Slice patterns. Rust 2018 will let you do just that. Non-reference patterns include all patterns except bindings, wildcard patterns (_), const patterns of reference types, and reference patterns. Slice::fill prototype.. C++ ships with std::fill which fills a range of memory with a given byte. Subslice patterns. Backstory: slice patterns It is already possible to use slice patterns on stable Rust to match on arrays and slices. Being used to Haskell and their pattern matching behavior, I always forget how cumbersome it is to match on an arbitrary slice in Rust. For example, say we want to accept a … This works the same way but uses the Copy trait instead of Clone, and is a direct wrapper of memcpy. If a binding pattern does not explicitly have ref , ref mut , or mut , then it uses the default binding mode to determine how the variable is bound. Issue 2067 on the RFCs repo proposes a safe wrapper around memset(3) call. Stabilization report The following is the stabilization report for #![feature(slice_patterns)]. slice::repeat. Tracking issue: #62254 Version target: 1.42 (2020-01-30 => beta, 2020-03-12 => stable).
Up until now, we've had the ~split_first~ method (and split_at ) on slices, which I can never remember the name of, which returns an Option , and which doesn't let you do arbitrary match-stuff (such as using match guards, for instance). The advanced_slice_patterns gate lets you use .. to indicate any number of elements inside a pattern matching a slice. () A macro, which is a shorter, more memorable, and convenient version of unimplemented!(). They looked like this: This wildcard can only be used once for a given array. This annotation is not yet available to use in stable Rust; if you are interested in using it in your own code, you can follow its progress by watching this tracking issue. In Rust 1.40.0 the following functions and macros were stabilized: todo! The compiler can optimize clone_from_slice to be equivalent to copy_from_slice when applicable, but it can still be useful. With Rust 1.40.0, the following function became const fn: is_power_of_two for unsigned integers; Additions to the standard library. Rust currently doesn't have a standard library equivalent for that.
As of Rust 1.9, you can also use copy_from_slice(). In Rust 1.26, we stabilized "slice patterns," which let you match on slices. Have you ever tried to pattern match on the contents and structure of a slice? If there's an identifier before the .. , the result of the slice will be bound to that name.