marine_macro_impl/
wasm_type.rs

1/*
2 * Copyright 2020 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use proc_macro2::TokenStream;
18
19/// Raw Wasm types according to the spec except i128.
20pub enum RustType {
21    U8,
22    U16,
23    U32,
24    U64,
25    I8,
26    I16,
27    I32,
28    I64,
29    F32,
30    F64,
31}
32
33impl quote::ToTokens for RustType {
34    fn to_tokens(&self, tokens: &mut TokenStream) {
35        let call_site = proc_macro2::Span::call_site();
36        match self {
37            RustType::U8 => syn::Ident::new("u8", call_site).to_tokens(tokens),
38            RustType::U16 => syn::Ident::new("u16", call_site).to_tokens(tokens),
39            RustType::U32 => syn::Ident::new("u32", call_site).to_tokens(tokens),
40            RustType::U64 => syn::Ident::new("u64", call_site).to_tokens(tokens),
41            RustType::I8 => syn::Ident::new("i8", call_site).to_tokens(tokens),
42            RustType::I16 => syn::Ident::new("i16", call_site).to_tokens(tokens),
43            RustType::I32 => syn::Ident::new("i32", call_site).to_tokens(tokens),
44            RustType::I64 => syn::Ident::new("i64", call_site).to_tokens(tokens),
45            RustType::F32 => syn::Ident::new("f32", call_site).to_tokens(tokens),
46            RustType::F64 => syn::Ident::new("f64", call_site).to_tokens(tokens),
47        }
48    }
49}