/rust/registry/src/index.crates.io-6f17d22bba15001f/wasm-encoder-0.4.1/src/modules.rs
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | use super::*; | 
| 2 |  |  | 
| 3 |  | /// An encoder for the module section. | 
| 4 |  | /// | 
| 5 |  | /// Note that this is part of the [module linking proposal][proposal] and is | 
| 6 |  | /// not currently part of stable WebAssembly. | 
| 7 |  | /// | 
| 8 |  | /// [proposal]: https://github.com/webassembly/module-linking | 
| 9 |  | /// | 
| 10 |  | /// # Example | 
| 11 |  | /// | 
| 12 |  | /// ``` | 
| 13 |  | /// use wasm_encoder::{ModuleSection, Module}; | 
| 14 |  | /// | 
| 15 |  | /// let mut modules = ModuleSection::new(); | 
| 16 |  | /// modules.module(&Module::new()); | 
| 17 |  | /// modules.module(&Module::new()); | 
| 18 |  | /// | 
| 19 |  | /// let mut module = Module::new(); | 
| 20 |  | /// module.section(&modules); | 
| 21 |  | /// | 
| 22 |  | /// let wasm_bytes = module.finish(); | 
| 23 |  | /// ``` | 
| 24 |  | #[derive(Clone, Debug)] | 
| 25 |  | pub struct ModuleSection { | 
| 26 |  |     bytes: Vec<u8>, | 
| 27 |  |     num_added: u32, | 
| 28 |  | } | 
| 29 |  |  | 
| 30 |  | impl ModuleSection { | 
| 31 |  |     /// Create a new code section encoder. | 
| 32 | 0 |     pub fn new() -> ModuleSection { | 
| 33 | 0 |         ModuleSection { | 
| 34 | 0 |             bytes: vec![], | 
| 35 | 0 |             num_added: 0, | 
| 36 | 0 |         } | 
| 37 | 0 |     } Unexecuted instantiation: <wasm_encoder::modules::ModuleSection>::newUnexecuted instantiation: <wasm_encoder::modules::ModuleSection>::newUnexecuted instantiation: <wasm_encoder::modules::ModuleSection>::newUnexecuted instantiation: <wasm_encoder::modules::ModuleSection>::newUnexecuted instantiation: <wasm_encoder::modules::ModuleSection>::newUnexecuted instantiation: <wasm_encoder::modules::ModuleSection>::newUnexecuted instantiation: <wasm_encoder::modules::ModuleSection>::new | 
| 38 |  |  | 
| 39 |  |     /// Writes a dmodule into this module code section. | 
| 40 | 0 |     pub fn module(&mut self, module: &Module) -> &mut Self { | 
| 41 | 0 |         self.bytes.extend( | 
| 42 | 0 |             encoders::u32(u32::try_from(module.bytes.len()).unwrap()) | 
| 43 | 0 |                 .chain(module.bytes.iter().copied()), | 
| 44 | 0 |         ); | 
| 45 | 0 |         self.num_added += 1; | 
| 46 | 0 |         self | 
| 47 | 0 |     } | 
| 48 |  | } | 
| 49 |  |  | 
| 50 |  | impl Section for ModuleSection { | 
| 51 | 0 |     fn id(&self) -> u8 { | 
| 52 | 0 |         SectionId::Module.into() | 
| 53 | 0 |     } Unexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::idUnexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::idUnexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::idUnexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::idUnexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::idUnexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::idUnexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::id | 
| 54 |  |  | 
| 55 | 0 |     fn encode<S>(&self, sink: &mut S) | 
| 56 | 0 |     where | 
| 57 | 0 |         S: Extend<u8>, | 
| 58 | 0 |     { | 
| 59 | 0 |         let num_added = encoders::u32(self.num_added); | 
| 60 | 0 |         let n = num_added.len(); | 
| 61 | 0 |         sink.extend( | 
| 62 | 0 |             encoders::u32(u32::try_from(n + self.bytes.len()).unwrap()) | 
| 63 | 0 |                 .chain(num_added) | 
| 64 | 0 |                 .chain(self.bytes.iter().copied()), | 
| 65 | 0 |         ); | 
| 66 | 0 |     } Unexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::encode::<alloc::vec::Vec<u8>>Unexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::encode::<alloc::vec::Vec<u8>>Unexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::encode::<_>Unexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::encode::<alloc::vec::Vec<u8>>Unexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::encode::<alloc::vec::Vec<u8>>Unexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::encode::<alloc::vec::Vec<u8>>Unexecuted instantiation: <wasm_encoder::modules::ModuleSection as wasm_encoder::Section>::encode::<alloc::vec::Vec<u8>> | 
| 67 |  | } |