1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; use crate::ScalarType; #[derive(Debug)] pub enum FieldRef { Name(String), ArrayAccess(usize), TupleAccess(usize), } #[derive(Debug, Clone, Copy)] pub enum Target { Direct, Buf(usize), Stream(usize), } impl Target { pub fn unwrap_buf(&self) -> usize { match self { Target::Buf(x) => *x, _ => unimplemented!(), } } } #[derive(Clone, Copy, Debug)] pub enum PrimitiveType { Bool, F32, F64, Scalar(ScalarType), } impl PrimitiveType { pub fn size(&self) -> u64 { match self { PrimitiveType::Bool => 1, PrimitiveType::F32 => 4, PrimitiveType::F64 => 8, PrimitiveType::Scalar(s) => s.size(), } } } impl ToString for PrimitiveType { fn to_string(&self) -> String { match self { PrimitiveType::Bool => "bool".to_string(), PrimitiveType::F32 => "f32".to_string(), PrimitiveType::F64 => "f64".to_string(), PrimitiveType::Scalar(s) => s.to_string(), } } } impl ToTokens for PrimitiveType { fn to_tokens(&self, tokens: &mut TokenStream) { match self { PrimitiveType::Bool => tokens.append(format_ident!("bool")), PrimitiveType::F32 => tokens.append(format_ident!("f32")), PrimitiveType::F64 => tokens.append(format_ident!("f64")), PrimitiveType::Scalar(s) => tokens.append(format_ident!("{}", &s.to_string())), } } } pub mod encode; pub mod decode;