-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathmodule.rs
More file actions
45 lines (38 loc) · 792 Bytes
/
module.rs
File metadata and controls
45 lines (38 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::fmt;
pub enum X {
A,
B,
}
pub struct X_List {
x: X,
tail: Option<Box<X_List>>,
}
pub fn length(list: X_List) -> usize {
match list {
X_List { x: _, tail: None } => 1,
X_List {
x: _,
tail: Some(tail),
} => 1 + length(*tail),
}
}
pub trait AsString {
fn as_string(&self) -> &str;
}
impl AsString for X {
fn as_string(&self) -> &str {
match self {
X::A => "a",
X::B => "b",
}
}
}
impl fmt::Display for X {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_string())
}
}
pub const X_A: X = X::A;
pub static X_B: X = X::B;
pub use std::fs::create_dir as mkdir;
pub use std::{fs::*, path::PathBuf};