VarWidth::String(width) => *width.min(&32) as u32,
}
}
+
+ pub fn from_raw(raw: impl Into<i32>) -> Result<Self, ()> {
+ let raw: i32 = raw.into();
+ match raw {
+ 0 => Ok(Self::Numeric),
+ 1..=255 => Ok(Self::String(raw as u16)),
+ _ => Err(()),
+ }
+ }
}
impl From<VarWidth> for VarType {
pub encoding: &'static Encoding,
}
+#[derive(Debug)]
pub struct DuplicateVariableName;
impl Dictionary {
}
}
- pub fn add_var(&mut self, variable: Variable) -> Result<(), DuplicateVariableName> {
- if self.variables.insert(ByIdentifier::new(variable)) {
- Ok(())
+ pub fn add_var(&mut self, variable: Variable) -> Result<usize, DuplicateVariableName> {
+ let (index, inserted) = self.variables.insert_full(ByIdentifier::new(variable));
+ if inserted {
+ Ok(index)
} else {
Err(DuplicateVariableName)
}