// SPDX-FileCopyrightText: 2017 - 2023 Kamila Borowska <kamila@borowska.pw> // SPDX-FileCopyrightText: 2021 Bruno Corrêa Zimmermann <brunoczim@gmail.com> // SPDX-FileCopyrightText: 2022 philipp <descpl@yahoo.de> // // SPDX-License-Identifier: MIT OR Apache-2.0
use core::cmp::Ordering; use core::convert::Infallible;
/// Enum mapping type. /// /// This trait is implemented by `#[derive(Enum)]`. /// /// This trait is also implemented by `bool` and `u8`. While `u8` is /// strictly speaking not an actual enum, there are good reasons to consider /// it like one, as array of `u8` keys is a relatively common pattern. pubtraitEnum: Sized { /// Length of the enum. const LENGTH: usize;
/// Takes an usize, and returns an element matching `into_usize` function. fn from_usize(value: usize) -> Self; /// Returns an unique identifier for a value within range of `0..Array::LENGTH`. fn into_usize(self) -> usize;
}
/// Trait associating enum with an array. /// /// This exists due to limitations of Rust compiler that prevent arrays from using /// associated constants in structures. The array length must match `LENGTH` of an /// `Enum`. pubtrait EnumArray<V>: Enum { /// Representation of an enum map for type `V`. type Array: Array<V>;
}
/// Array for enum-map storage. /// /// This trait is inteded for primitive array types (with fixed length). /// /// # Safety /// /// The array length needs to match actual storage. pubunsafetrait Array<V> { // This is necessary duplication because the length in Enum trait can be // provided by user and may not be trustworthy for unsafe code. const LENGTH: usize;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.