27 lines
666 B
Rust
27 lines
666 B
Rust
//! [`Operation`] parsing code.
|
|
|
|
/// The list of operations to perform.
|
|
#[derive(Debug)]
|
|
pub enum Operation {
|
|
/// Set the mask using a given string.
|
|
SetMask(String),
|
|
/// Set the memory of an address to a given value.
|
|
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)
|
|
}
|
|
}
|