message: rust: add Module and parse
diff: mod sys;
  +use std::ptr::NonNull;
  +
  /// Parse and validate the input according to WebAssembly 1.0 rules. Returns true if the supplied input is valid.
  pub fn validate<T: AsRef<[u8]>>(input: T) -> bool {
  unsafe { sys::fizzy_validate(input.as_ref().as_ptr(), input.as_ref().len()) }
  }
  +/// A parsed and validated WebAssembly 1.0 module.
  +// NOTE: cannot use NonNull here given this is *const
  +pub struct Module(*const sys::FizzyModule);
  +
  +impl Drop for Module {
  + fn drop(&mut self) {
  + unsafe { sys::fizzy_free_module(self.0) }
  + }
  +}
  +
  +/// Parse and validate the input according to WebAssembly 1.0 rules.
  +pub fn parse<T: AsRef<[u8]>>(input: &T) -> Result<Module, ()> {
  + let ptr = unsafe { sys::fizzy_parse(input.as_ref().as_ptr(), input.as_ref().len()) };
  + if ptr.is_null() {
  + return Err(());
  + }
  + Ok(Module { 0: ptr })
  +}
  +
  #[cfg(test)]
  mod tests {
  use super::*;
  @@ -34,4 +55,10 @@ mod tests {
  false
  );
  }
  +
  + #[test]
  + fn parse_wasm() {
  + assert!(parse(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]).is_ok());
  + assert!(parse(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x01]).is_err());
  + }
  }
  