1
Fork 0
advent-of-code/source/year_2020/day_14/operation.rs

22 lines
500 B
Rust
Raw Normal View History

2022-10-03 16:02:40 +00:00
#[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)
}
}