fix(runtime-c-api) Fix From<c_uchar> for Version.

0 matches to `Unknown`, 1 matches to `Snapshot0` and 2 matches to
`Snapshot1`.
This commit is contained in:
Ivan Enderlin
2019-12-04 14:48:12 +01:00
parent 90f3c894c1
commit 345511a4f9
3 changed files with 24 additions and 12 deletions

View File

@ -3,22 +3,22 @@ use crate::get_slice_checked;
use std::{path::PathBuf, ptr, str}; use std::{path::PathBuf, ptr, str};
use wasmer_wasi as wasi; use wasmer_wasi as wasi;
#[derive(Debug)] #[derive(Debug, PartialEq)]
#[repr(u8)] #[repr(u8)]
pub enum Version { pub enum Version {
/// Version cannot be detected or is unknown. /// Version cannot be detected or is unknown.
Unknown, Unknown = 0,
/// `wasi_unstable`. /// `wasi_unstable`.
Snapshot0, Snapshot0 = 1,
/// `wasi_snapshot_preview1`. /// `wasi_snapshot_preview1`.
Snapshot1, Snapshot1 = 2,
} }
impl From<c_uchar> for Version { impl From<c_uchar> for Version {
fn from(value: c_uchar) -> Self { fn from(value: c_uchar) -> Self {
match value { match value {
0 => Self::Snapshot0, 1 => Self::Snapshot0,
1 => Self::Snapshot1, 2 => Self::Snapshot1,
_ => Self::Unknown, _ => Self::Unknown,
} }
} }
@ -178,3 +178,15 @@ pub unsafe extern "C" fn wasmer_wasi_generate_default_import_object() -> *mut wa
Box::into_raw(import_object) as *mut wasmer_import_object_t Box::into_raw(import_object) as *mut wasmer_import_object_t
} }
#[cfg(test)]
mod tests {
use super::Version;
#[test]
fn test_versions_from_uint() {
assert_eq!(Version::Unknown, 0.into());
assert_eq!(Version::Snapshot0, 1.into());
assert_eq!(Version::Snapshot1, 2.into());
}
}

View File

@ -29,15 +29,15 @@ enum Version {
/** /**
* Version cannot be detected or is unknown. * Version cannot be detected or is unknown.
*/ */
Unknown, Unknown = 0,
/** /**
* `wasi_unstable`. * `wasi_unstable`.
*/ */
Snapshot0, Snapshot0 = 1,
/** /**
* `wasi_snapshot_preview1`. * `wasi_snapshot_preview1`.
*/ */
Snapshot1, Snapshot1 = 2,
}; };
typedef uint8_t Version; typedef uint8_t Version;

View File

@ -27,11 +27,11 @@
enum class Version : uint8_t { enum class Version : uint8_t {
/// Version cannot be detected or is unknown. /// Version cannot be detected or is unknown.
Unknown, Unknown = 0,
/// `wasi_unstable`. /// `wasi_unstable`.
Snapshot0, Snapshot0 = 1,
/// `wasi_snapshot_preview1`. /// `wasi_snapshot_preview1`.
Snapshot1, Snapshot1 = 2,
}; };
/// List of export/import kinds. /// List of export/import kinds.