MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm / write_cstring_bytes

Method write_cstring_bytes

crates/tinywasm/src/reference.rs:285–290  ·  view source on GitHub ↗

Copies a UTF-8 string into memory and appends a trailing nul byte.

(&self, store: &mut Store, offset: usize, string: &str)

Source from the content-addressed store, hash-verified

283
284 /// Copies a UTF-8 string into memory and appends a trailing nul byte.
285 pub fn write_cstring_bytes(&self, store: &mut Store, offset: usize, string: &str) -> Result<()> {
286 let mut bytes = Vec::with_capacity(string.len() + 1);
287 bytes.extend_from_slice(string.as_bytes());
288 bytes.push(0);
289 self.copy_from_slice(store, offset, &bytes)
290 }
291
292 /// Reads a C-style string from memory.
293 pub fn read_cstring(&self, store: &Store, offset: usize, len: usize) -> Result<CString> {

Callers 1

newMethod · 0.80

Calls 3

lenMethod · 0.45
pushMethod · 0.45
copy_from_sliceMethod · 0.45

Tested by

no test coverage detected