Trait Intern

Source
pub unsafe trait Intern:
    Hash
    + PartialEq
    + Eq {
    type Primitive: Sized + Copy + Debug;

    // Required methods
    fn as_bytes(&self) -> &[Self::Primitive];
    unsafe fn from_bytes(bytes: &[Self::Primitive]) -> &Self;
}
Expand description

Trait implemented by different types of strings that can be interned.

§Safety

It should be alwas valid to reinterpret bytes of Self as &[Self::Primitive] using Intern::as_bytes.

It should be valid to reinterpret bytes copied from Intern::as_bytes. as &Self using Intern::from_bytes. Even if they were moved in memory.

Required Associated Types§

Source

type Primitive: Sized + Copy + Debug

A primitive type that has the same alignment as Self.

Required Methods§

Source

fn as_bytes(&self) -> &[Self::Primitive]

Source

unsafe fn from_bytes(bytes: &[Self::Primitive]) -> &Self

§Safety

See Safety section in the trait doc.

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.

Implementations on Foreign Types§

Source§

impl Intern for str

Source§

type Primitive = u8

Source§

fn as_bytes(&self) -> &[u8]

Source§

unsafe fn from_bytes(bytes: &[u8]) -> &Self

Source§

impl Intern for CStr

Source§

type Primitive = u8

Source§

fn as_bytes(&self) -> &[u8]

Source§

unsafe fn from_bytes(bytes: &[u8]) -> &Self

Source§

impl Intern for OsStr

Source§

type Primitive = u8

Source§

fn as_bytes(&self) -> &[u8]

Source§

unsafe fn from_bytes(bytes: &[u8]) -> &Self

Source§

impl Intern for [char]

Source§

type Primitive = char

Source§

fn as_bytes(&self) -> &[char]

Source§

unsafe fn from_bytes(bytes: &[char]) -> &Self

Source§

impl Intern for [u8]

Source§

type Primitive = u8

Source§

fn as_bytes(&self) -> &[u8]

Source§

unsafe fn from_bytes(bytes: &[u8]) -> &Self

Implementors§