Mercurial > core / rust/lib/sxp/src/nostd.rs
changeset 8: |
1227f932b628 |
child: |
0ccbbd142694 |
author: |
ellis <ellis@rwest.io> |
date: |
Tue, 17 Oct 2023 20:36:37 -0400 |
permissions: |
-rw-r--r-- |
description: |
rust import |
1 //! nostd.rs --- nostd support 3 //! Reimplements core logic and types from `std::io` in an `alloc`-friendly 7 use core::fmt::{self, Display}; 14 // I/O errors can never occur in no-std mode. All our no-std I/O implementations 18 impl Display for Error { 19 fn fmt(&self, _formatter: &mut fmt::Formatter<'_>) -> fmt::Result { 25 pub(crate) fn new(_kind: ErrorKind, _error: &'static str) -> Error { 30 pub type Result<T> = result::Result<T, Error>; 33 fn write(&mut self, buf: &[u8]) -> Result<usize>; 35 fn write_all(&mut self, buf: &[u8]) -> Result<()> { 36 // All our Write impls in no_std mode always write the whole buffer in 37 // one call infallibly. 38 let result = self.write(buf); 39 debug_assert!(result.is_ok()); 40 debug_assert_eq!(result.unwrap_or(0), buf.len()); 44 fn flush(&mut self) -> Result<()>; 47 impl<W: Write> Write for &mut W { 49 fn write(&mut self, buf: &[u8]) -> Result<usize> { 54 fn write_all(&mut self, buf: &[u8]) -> Result<()> { 55 (*self).write_all(buf) 59 fn flush(&mut self) -> Result<()> { 64 impl Write for Vec<u8> { 66 fn write(&mut self, buf: &[u8]) -> Result<usize> { 67 self.extend_from_slice(buf); 72 fn write_all(&mut self, buf: &[u8]) -> Result<()> { 73 self.extend_from_slice(buf); 78 fn flush(&mut self) -> Result<()> {