ring/
polyfill.rs

1// Copyright 2015-2016 Brian Smith.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15//! Polyfills for functionality that will (hopefully) be added to Rust's
16//! standard library soon.
17
18#[inline(always)]
19pub const fn u64_from_usize(x: usize) -> u64 {
20    x as u64
21}
22
23pub fn usize_from_u32(x: u32) -> usize {
24    x as usize
25}
26
27pub mod slice {
28    // https://github.com/rust-lang/rust/issues/27750
29    // https://internals.rust-lang.org/t/stabilizing-basic-functions-on-arrays-and-slices/2868
30    #[inline(always)]
31    pub fn fill<T>(dest: &mut [T], value: T)
32    where
33        T: Copy,
34    {
35        for d in dest {
36            *d = value;
37        }
38    }
39}