2020-04-09 10:48:50 +02:00
|
|
|
//! This module defines the WIT types.
|
|
|
|
|
|
|
|
use crate::vec1::Vec1;
|
2020-07-25 11:01:41 +03:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-04-09 10:48:50 +02:00
|
|
|
|
|
|
|
/// Represents the types supported by WIT.
|
2020-08-20 16:01:33 +03:00
|
|
|
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
|
2020-04-09 10:48:50 +02:00
|
|
|
pub enum InterfaceType {
|
|
|
|
/// A 8-bits signed integer.
|
|
|
|
S8,
|
|
|
|
|
|
|
|
/// A 16-bits signed integer.
|
|
|
|
S16,
|
|
|
|
|
|
|
|
/// A 32-bits signed integer.
|
|
|
|
S32,
|
|
|
|
|
|
|
|
/// A 64-bits signed integer.
|
|
|
|
S64,
|
|
|
|
|
|
|
|
/// A 8-bits unsigned integer.
|
|
|
|
U8,
|
|
|
|
|
|
|
|
/// A 16-bits unsigned integer.
|
|
|
|
U16,
|
|
|
|
|
|
|
|
/// A 32-bits unsigned integer.
|
|
|
|
U32,
|
|
|
|
|
|
|
|
/// A 64-bits unsigned integer.
|
|
|
|
U64,
|
|
|
|
|
|
|
|
/// A 32-bits float.
|
|
|
|
F32,
|
|
|
|
|
|
|
|
/// A 64-bits float.
|
|
|
|
F64,
|
|
|
|
|
|
|
|
/// A string.
|
|
|
|
String,
|
|
|
|
|
2020-07-09 02:46:54 +03:00
|
|
|
/// A byte array.
|
|
|
|
ByteArray,
|
|
|
|
|
2020-04-09 10:48:50 +02:00
|
|
|
/// An `any` reference.
|
|
|
|
Anyref,
|
|
|
|
|
|
|
|
/// A 32-bits integer (as defined in WebAssembly core).
|
|
|
|
I32,
|
|
|
|
|
|
|
|
/// A 64-bits integer (as defiend in WebAssembly core).
|
|
|
|
I64,
|
|
|
|
|
2020-08-13 21:02:23 +03:00
|
|
|
/// A record contains type name.
|
|
|
|
// TODO: consider making it &str
|
|
|
|
Record(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Represents a record field type.
|
2020-08-20 16:01:33 +03:00
|
|
|
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
|
2020-08-13 21:02:23 +03:00
|
|
|
pub struct RecordFieldType {
|
|
|
|
// TODO: make name optional to support structures with anonymous fields in Rust
|
|
|
|
/// A field name.
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
/// A field type.
|
|
|
|
pub ty: InterfaceType,
|
2020-04-09 10:48:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Represents a record type.
|
2020-06-22 16:46:11 +03:00
|
|
|
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
|
2020-04-09 10:48:50 +02:00
|
|
|
pub struct RecordType {
|
2020-08-13 21:02:23 +03:00
|
|
|
/// A record name.
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
/// Types and names representing the fields.
|
2020-04-09 12:10:48 +02:00
|
|
|
/// A record must have at least one field, hence the
|
|
|
|
/// [`Vec1`][crate::vec1::Vec1].
|
2020-08-13 21:02:23 +03:00
|
|
|
pub fields: Vec1<RecordFieldType>,
|
2020-04-09 10:48:50 +02:00
|
|
|
}
|