MCPcopy Create free account
hub / github.com/explodingcamera/tinywasm / seek

Method seek

crates/tinywasm/src/reference.rs:134–156  ·  view source on GitHub ↗
(&mut self, pos: crate::std::io::SeekFrom)

Source from the content-addressed store, hash-verified

132#[cfg(feature = "std")]
133impl crate::std::io::Seek for MemoryCursor<'_> {
134 fn seek(&mut self, pos: crate::std::io::SeekFrom) -> crate::std::io::Result<u64> {
135 let len = self.memory.inner.len() as i128;
136 let current = i128::from(self.position);
137
138 let next = match pos {
139 crate::std::io::SeekFrom::Start(offset) => i128::from(offset),
140 crate::std::io::SeekFrom::End(offset) => len + i128::from(offset),
141 crate::std::io::SeekFrom::Current(offset) => current + i128::from(offset),
142 };
143
144 if next < 0 {
145 return Err(crate::std::io::Error::new(
146 crate::std::io::ErrorKind::InvalidInput,
147 "invalid seek before start",
148 ));
149 }
150
151 let next = u64::try_from(next).map_err(|_| {
152 crate::std::io::Error::new(crate::std::io::ErrorKind::InvalidInput, "invalid seek position")
153 })?;
154 self.position = next;
155 Ok(next)
156 }
157}
158
159impl Memory {

Callers 3

build_importsFunction · 0.80
save_csvMethod · 0.80

Calls 1

lenMethod · 0.45

Tested by 2

save_csvMethod · 0.64