mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
wasm: Make NameSection easier to manipulate
This commit is contained in:
parent
66c0c423b3
commit
376cbbc4b2
3 changed files with 48 additions and 46 deletions
|
@ -18,6 +18,13 @@ impl Serialize for str {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for &str {
|
||||
fn serialize<T: SerialBuffer>(&self, buffer: &mut T) {
|
||||
buffer.encode_u32(self.len() as u32);
|
||||
buffer.append_slice(self.as_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for u8 {
|
||||
fn serialize<T: SerialBuffer>(&self, buffer: &mut T) {
|
||||
buffer.append_u8(*self);
|
||||
|
@ -67,6 +74,13 @@ impl<S: Serialize> Serialize for Option<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<A: Serialize, B: Serialize> Serialize for (A, B) {
|
||||
fn serialize<T: SerialBuffer>(&self, buffer: &mut T) {
|
||||
self.0.serialize(buffer);
|
||||
self.1.serialize(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
/// Write an unsigned integer into the provided buffer in LEB-128 format, returning byte length
|
||||
///
|
||||
/// All integers in Wasm are variable-length encoded, which saves space for small values.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue