Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_syntax/src/key.rs

597 bytes, 10 runs

created by r1870400018:1051, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use oxedyne_fe2o3_core::ok;
2
3use std::{
4 fmt,
5};
6
7#[derive(Clone, Debug, Eq, Ord, PartialOrd, PartialEq)]
8pub enum Key {
9 Id(u16),
10 Str(String),
11}
12
13impl From<&str> for Key {
14 fn from(s: &str) -> Self {
15 Key::Str(s.to_string())
16 }
17}
18
19impl From<String> for Key {
20 fn from(s: String) -> Self {
21 Key::Str(s)
22 }
23}
24
25impl fmt::Display for Key {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match &*self {
28 Key::Id(id) => ok!(write!(f, "{}", id)),
29 Key::Str(s) => ok!(write!(f, "{}", s)),
30 }
31 Ok(())
32 }
33}