diff --git a/bip/src/bp.rs b/bip/src/bp.rs index 09d219e..14005cf 100644 --- a/bip/src/bp.rs +++ b/bip/src/bp.rs @@ -28,6 +28,7 @@ pub enum Error { BadWrite(std::io::Error), NotDefined, ExpectedID, + RedefData, } impl fmt::Display for Error { @@ -37,6 +38,7 @@ impl fmt::Display for Error { Self::BadWrite(e) => write!(f, "{}", e), Self::NotDefined => write!(f, "undefined data type"), Self::ExpectedID => write!(f, "expected identifier"), + Self::RedefData => write!(f, "redefining existing datatype"), } } } @@ -189,7 +191,9 @@ impl Writer { if s == "data" { let lhs = lhs.clone(); let data = self.parse_data_type(rhs); - self.data.insert(lhs, data); + self.data + .insert(lhs, data) + .map_or(Ok(()), |_| Err(Error::RedefData))?; } else { self.parse_id(rhs)?; }