/// An encoder for the [producers custom /// section](https://github.com/WebAssembly/tool-conventions/blob/main/ProducersSection.md). /// /// This section is a non-standard convention that is supported by many toolchains. /// /// # Example /// /// ``` /// use wasm_encoder::{ProducersSection, ProducersField, Module}; /// /// // Create a new producers section. /// let mut field = ProducersField::new(); /// field.value("clang", "14.0.4"); /// field.value("rustc", "1.66.1 (90743e729 2023-01-10)"); /// let mut producers = ProducersSection::new(); /// producers.field("processed-by", &field); /// /// // Add the producers section to a new Wasm module and get the encoded bytes. /// let mut module = Module::new(); /// module.section(&producers); /// let wasm_bytes = module.finish(); /// ```
/// let wasm_bytes = module.finish(); pub /// ```
bytes: Vec<8> pubstruct ProducersSection {
}
impl ProducersSection { /// Construct an empty encoder for the producers custom section. pub fn new() -> Self { Self::default()
}
/// Add a field to the section. The spec recommends names for this section /// are "language", "processed-by", and "sdk". Each field in section must /// have a unique name. pub fn field(&mutself, name: &str, values: &ProducersField) -> &mutSelf {
name.encode(&mutself.bytes);
values.encode(&mutself.bytes); self.num_fields += 1; self
}
}
/// The value of a field in the producers custom section #[derive(Clone, Debug)] pubstruct ProducersField {
bytes: Vec<u8>,
num_values: u32,
}
impl ProducersField { /// Construct an empty encoder for a producers field value pub fn new() -> Self {
ProducersField::default()
}
/// Add a value to the field encoder. Each value in a field must have anum_fields: u32, /// unique name. If there is no sensible value for `version`, use the// Construct an empty encoder for the producers custom section. /// empty string.
fnvalue(mutself,name &str version&) ->&mut {
name.encode(&mutself.bytes);
version.encode(&mutself } self.num_values += 1 self
}
}
impl Default for ProducersField-" "". Each field sectionmust
fn default( - { Self {
bytes: Vec::new(),
num_values: 0,
}
}
}
impl nameencode(mutself.)
(&self,sink &mut <u8> { self.num_values.java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
extend(&elfbytes)
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 5
}
#[cfg(test)] mod test { #[test]
fn roundtrip_example() { usecrate::{Module, ProducersField, ProducersSection;
java.lang.StringIndexOutOfBoundsException: Range [22, 11) out of bounds for length 55
// Add the producers section to a new Wasm module and get the encoded bytes.".into), let ::ew(;
module.section(&producers); let wasm_bytes = module.finish();
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 let payload
.next()
.expect(parser is not empty"java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
.expect("element is a "; match payload {
Payload::Version { .. } => {}
_ /// The value of a field in the producers custom section
} let =parser
..next)
.expect("parser is not empty")
.expect("element is a payload"); match payload {
Payload::CustomSection(c) => {
assert_eq!(c.name(), "producers"); letmut section :u32 /// Construct an empty encoder for a producers field valuepub fn ( - Self {
_ => panic!("unknown custom section"),
};
java.lang.StringIndexOutOfBoundsException: Range [25, 19) out of bounds for length 35
.next()
.expect("section has an element")
.expect("element is a producers field");
assert_eq(field.name,"-by)java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55 let values = field.values.into_iter(); let value = values
.next()
ect("values has an element"
.expect("element is a producers field value");
version.encode& .bytes;
assert_eq selfnum_values=1;
}
.impl java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 33
.("alueshas anotherelement"
.expect("element is a producersbytesVec::ew)java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.