protospec_build/prelude/
resolver.rs

1use super::*;
2pub struct PreludeImportResolver<T: ImportResolver + 'static>(pub T);
3
4impl<T: ImportResolver + 'static> ImportResolver for PreludeImportResolver<T> {
5    fn normalize_import(&self, import: &str) -> Result<String> {
6        self.0.normalize_import(import)
7    }
8
9    fn resolve_import(&self, import: &str) -> Result<Option<String>> {
10        self.0.resolve_import(import)
11    }
12
13    fn resolve_ffi_transform(&self, transform: &str) -> Result<Option<ForeignTransformObj>> {
14        Ok(match transform {
15            "base64" => Some(Box::new(Base64Transform)),
16            "gzip" => Some(Box::new(GzipTransform)),
17            x => self.0.resolve_ffi_transform(x)?,
18        })
19    }
20
21    fn resolve_ffi_type(&self, import: &str) -> Result<Option<ForeignTypeObj>> {
22        Ok(match import {
23            "v8" => Some(Box::new(VarInt::new(ScalarType::I8))),
24            "v16" => Some(Box::new(VarInt::new(ScalarType::I16))),
25            "v32" => Some(Box::new(VarInt::new(ScalarType::I32))),
26            "v64" => Some(Box::new(VarInt::new(ScalarType::I64))),
27            "v128" => Some(Box::new(VarInt::new(ScalarType::I128))),
28            "utf8" => Some(Box::new(Utf8)),
29            "utf16" => Some(Box::new(Utf16)),
30            x => self.0.resolve_ffi_type(x)?,
31        })
32    }
33
34    fn resolve_ffi_function(&self, name: &str) -> Result<Option<ForeignFunctionObj>> {
35        Ok(match name {
36            "len" => Some(Box::new(LenFunction)),
37            "pad" => Some(Box::new(PadFunction)),
38            x => self.0.resolve_ffi_function(x)?,
39        })
40    }
41}