pub trait StringIndex:
Copy
+ Send
+ Sync
+ 'static {
const TYPE_NAME: &'static str;
// Required methods
fn try_from_usize(value: usize) -> Option<Self>;
fn to_usize(self) -> usize;
}Expand description
Contract for integer types used by crate::StringId.
Self::try_from_usize is used at build and validation boundaries where
counts are computed as usize. Self::to_usize is used on lookup paths
for infallible indexing.
§Implementing this trait
This trait is already implemented for primitive unsigned integers (u8, u16, u32,
u64, usize). To implement it for custom wrapper types, use the
impl_string_index macro:
use lite_strtab::impl_string_index;
#[derive(Clone, Copy)]
#[repr(transparent)]
struct ProviderIdx(u16);
impl_string_index!(ProviderIdx: u16);Required Associated Constants§
Required Methods§
Sourcefn try_from_usize(value: usize) -> Option<Self>
fn try_from_usize(value: usize) -> Option<Self>
Converts a string index into this type.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.