pub struct Index<T> { /* private fields */ }Expand description
A branded index into a typed collection.
The phantom type T prevents mixing indices of different domains
(e.g. you cannot use a CharShapeIndex where a ParaShapeIndex
is expected).
Serializes as a plain usize, not as a struct.
§Examples
use hwpforge_foundation::{CharShapeIndex, ParaShapeIndex};
let cs = CharShapeIndex::new(5);
let ps = ParaShapeIndex::new(5);
// cs and ps have the same numeric value but are different types.
assert_eq!(cs.get(), ps.get());
// cs == ps; // Would not compile -- different phantom types!Implementations§
Source§impl<T> Index<T>
impl<T> Index<T>
Sourcepub const fn new(value: usize) -> Self
pub const fn new(value: usize) -> Self
Creates a new index with the given value.
No bounds checking is performed here; use checked_get
when accessing a collection.
Sourcepub const fn get(self) -> usize
pub const fn get(self) -> usize
Returns the raw usize value.
§Note
The caller is responsible for ensuring this index is within
the bounds of the target collection. Prefer checked_get
for safe access.
Sourcepub fn checked_get(self, max: usize) -> FoundationResult<usize>
pub fn checked_get(self, max: usize) -> FoundationResult<usize>
Returns the raw value after verifying it is less than max.
§Errors
Returns FoundationError::IndexOutOfBounds when
self.value >= max.
§Examples
use hwpforge_foundation::FontIndex;
let idx = FontIndex::new(3);
assert_eq!(idx.checked_get(10).unwrap(), 3);
assert!(idx.checked_get(2).is_err());Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Index<T>
impl<'de, T> Deserialize<'de> for Index<T>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T> JsonSchema for Index<T>
impl<T> JsonSchema for Index<T>
Source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreSource§impl<T> Ord for Index<T>
impl<T> Ord for Index<T>
Source§impl<T> PartialOrd for Index<T>
impl<T> PartialOrd for Index<T>
impl<T> Copy for Index<T>
impl<T> Eq for Index<T>
Auto Trait Implementations§
impl<T> Freeze for Index<T>
impl<T> RefUnwindSafe for Index<T>where
T: RefUnwindSafe,
impl<T> Send for Index<T>where
T: Send,
impl<T> Sync for Index<T>where
T: Sync,
impl<T> Unpin for Index<T>where
T: Unpin,
impl<T> UnwindSafe for Index<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.