Mercurial > core / rust/lib/sxp/src/nostd.rs
changeset 698: |
96958d3eb5b0 |
parent: |
0ccbbd142694
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
1 //! nostd.rs --- nostd support 3 //! Reimplements core logic and types from `std::io` in an `alloc`-friendly 16 // I/O errors can never occur in no-std mode. All our no-std I/O implementations 20 impl Display for Error { 21 fn fmt(&self, _formatter: &mut fmt::Formatter<'_>) -> fmt::Result { 27 pub(crate) fn new(_kind: ErrorKind, _error: &'static str) -> Error { 32 pub type Result<T> = result::Result<T, Error>; 35 fn write(&mut self, buf: &[u8]) -> Result<usize>; 37 fn write_all(&mut self, buf: &[u8]) -> Result<()> { 38 // All our Write impls in no_std mode always write the whole buffer in 39 // one call infallibly. 40 let result = self.write(buf); 41 debug_assert!(result.is_ok()); 42 debug_assert_eq!(result.unwrap_or(0), buf.len()); 46 fn flush(&mut self) -> Result<()>; 49 impl<W: Write> Write for &mut W { 51 fn write(&mut self, buf: &[u8]) -> Result<usize> { 56 fn write_all(&mut self, buf: &[u8]) -> Result<()> { 57 (*self).write_all(buf) 61 fn flush(&mut self) -> Result<()> { 66 impl Write for Vec<u8> { 68 fn write(&mut self, buf: &[u8]) -> Result<usize> { 69 self.extend_from_slice(buf); 74 fn write_all(&mut self, buf: &[u8]) -> Result<()> { 75 self.extend_from_slice(buf); 80 fn flush(&mut self) -> Result<()> {