22 lines
500 B
Rust
22 lines
500 B
Rust
#[derive(Debug)]
|
|
pub enum Operation {
|
|
SetMask(String),
|
|
SetMemory(i64, i64),
|
|
}
|
|
|
|
impl From<&str> for Operation {
|
|
fn from(input: &str) -> Self {
|
|
let mut split = input.split(" = ");
|
|
|
|
let operation = split.next().unwrap();
|
|
if operation == "mask" {
|
|
return Self::SetMask(split.next().unwrap().to_string());
|
|
}
|
|
|
|
let address = operation[4..operation.len() - 1].parse().unwrap();
|
|
let value = split.next().unwrap().parse().unwrap();
|
|
|
|
Self::SetMemory(address, value)
|
|
}
|
|
}
|