| 132 | #[cfg(feature = "std")] |
| 133 | impl 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 | |
| 159 | impl Memory { |