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

27 lines
666 B
Rust
Raw Normal View History

2024-01-14 21:04:10 +00:00
//! [`Operation`] parsing code.
/// The list of operations to perform.
2022-10-03 16:02:40 +00:00
#[derive(Debug)]
pub enum Operation {
2024-01-14 21:04:10 +00:00
/// Set the mask using a given string.
2022-10-03 16:02:40 +00:00
SetMask(String),
2024-01-14 21:04:10 +00:00
/// Set the memory of an address to a given value.
2022-10-03 16:02:40 +00:00
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)
}
}