cfd16_lib_impl/lib.rs
1//! Holds the trait Codeable for cfd16-lib, allowing the definition
2//! of a proc-macro.
3
4#![warn(missing_docs)]
5
6/// Processor's current mode of execution.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
8pub enum Mode {
9 /// Unpriviledged mode of execution without direct access to system
10 /// registers required for more complex (and unsafe) operations.
11 User,
12
13 /// Priviledged mode of execution used mostly for interrupt service
14 /// routines and Operating Systems.
15 Kernel,
16}
17
18/// Trait which allows for the encoding and decoding of instructions and
19/// portions thereof. This trait can only be implemented if it is
20/// impossible for the encoding of the implementing type to fail.
21pub trait Codable
22where
23 Self: Sized,
24{
25 /// Encodes the instruction or portion thereof.
26 fn encode(&self) -> u16;
27
28 /// Decodes the instruction given the current mode of execution.
29 fn decode(value: u16, mode: Mode) -> Option<Self>;
30}