fce_wit_parser/
extractor.rs1mod functions;
18mod wit;
19
20pub use functions::*;
21pub use wit::*;
22
23use crate::Result;
24use crate::WITParserError;
25
26use fce_wit_interfaces::FCEWITInterfaces;
27use std::path::Path;
28
29pub fn module_interface<P>(module_path: P) -> Result<ServiceInterface>
30where
31 P: AsRef<Path>,
32{
33 create_fce_it_with(module_path, |it| get_interface(&it))
34}
35
36pub fn module_raw_interface<P>(module_path: P) -> Result<FCEModuleInterface>
37where
38 P: AsRef<Path>,
39{
40 create_fce_it_with(module_path, |it| get_raw_interface(&it))
41}
42
43fn create_fce_it_with<P, T>(
44 module_path: P,
45 transformer: impl FnOnce(FCEWITInterfaces<'_>) -> Result<T>,
46) -> Result<T>
47where
48 P: AsRef<Path>,
49{
50 let module = walrus::ModuleConfig::new()
51 .parse_file(module_path)
52 .map_err(WITParserError::CorruptedWasmFile)?;
53 let raw_custom_section = extract_custom_section(&module)?;
54 let custom_section_bytes = raw_custom_section.as_ref();
55 let wit = extract_wit_from_bytes(custom_section_bytes)?;
56
57 let fce_interface = FCEWITInterfaces::new(wit);
58
59 transformer(fce_interface)
60}