1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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<Self, Self::Err> {
- 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<Self, Self::Err> {
- let integer = s.parse::<usize>();
- 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"),
- }
- }
- }
- }
|