W3cubDocs

/Rust

Trait collections::enum_set::CLike

pub trait CLike {
    fn to_usize(&self) -> usize;
    fn from_usize(_: usize) -> Self;
}
Deprecated since 1.16.0: long since replaced 🔬 This is a nightly-only experimental API. (enumset #37966)matches collection reform specification, waiting for dust to settle

An interface for casting C-like enum to usize and back. A typically implementation is as below.

#[repr(usize)]
enum Foo {
    A, B, C
}

impl CLike for Foo {
    fn to_usize(&self) -> usize {
        *self as usize
    }

    fn from_usize(v: usize) -> Foo {
        unsafe { mem::transmute(v) }
    }
}

Required Methods

Deprecated since 1.16.0: long since replaced 🔬 This is a nightly-only experimental API. (enumset #37966)matches collection reform specification, waiting for dust to settle

Converts a C-like enum to a usize.

Deprecated since 1.16.0: long since replaced 🔬 This is a nightly-only experimental API. (enumset #37966)matches collection reform specification, waiting for dust to settle

Converts a usize to a C-like enum.

Implementors

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/collections/enum_set/trait.CLike.html