use std::str::FromStr; pub enum CellLayout { Trusting, Wrapping, Unbounded } pub enum CellSize { Bits(usize), Modular(usize), Int } pub struct Options { pub cell_layout: CellLayout, pub memory_size: i64, pub cell_size: CellSize, } impl Default for Options { fn default() -> Self { Options { cell_layout: CellLayout::Trusting, memory_size: 0x10000, cell_size: CellSize::Bits(8), } } } impl FromStr for CellLayout { type Err = &'static str; fn from_str(s: &str) -> Result { match s { "trusting" => Ok(CellLayout::Trusting), "wrapping" => Ok(CellLayout::Wrapping), _ => Err("invalid cell layout"), } } } impl FromStr for CellSize { type Err = &'static str; fn from_str(s: &str) -> Result { let integer = s.parse::(); match integer { Ok(i) => Ok(CellSize::Bits(i)), Err(e) => match s { "8" => Ok(CellSize::Bits(8)), "16" => Ok(CellSize::Bits(16)), "32" => Ok(CellSize::Bits(16)), "int" => Ok(CellSize::Int), _ => Err("invalid cell size"), } } } }