Browse Source

Prepare for use of Write trait by renaming Write to WriteByte

Jeremy Soller 6 years ago
parent
commit
ef9fee5a2b

+ 1 - 1
Cargo.toml

@@ -9,7 +9,7 @@ crate-type = ["staticlib"]
 
 [workspace]
 members = ["src/crt0", "src/crti", "src/crtn", "cbindgen"]
-exclude = ["core_io"]
+exclude = ["core_io", "ralloc"]
 
 [build-dependencies]
 cc = "1.0.17"

+ 3 - 3
src/header/stdio/mod.rs

@@ -15,7 +15,7 @@ use header::stdlib::mkstemp;
 use header::string::strlen;
 use platform;
 use platform::types::*;
-use platform::{c_str, errno, Read, Write};
+use platform::{c_str, errno, ReadByte, WriteByte};
 use platform::{Pal, Sys};
 
 mod printf;
@@ -219,7 +219,7 @@ impl<'a> fmt::Write for LockGuard<'a> {
         }
     }
 }
-impl<'a> Write for LockGuard<'a> {
+impl<'a> WriteByte for LockGuard<'a> {
     fn write_u8(&mut self, byte: u8) -> fmt::Result {
         if !self.0.can_write() {
             return Err(Error);
@@ -231,7 +231,7 @@ impl<'a> Write for LockGuard<'a> {
         }
     }
 }
-impl<'a> Read for LockGuard<'a> {
+impl<'a> ReadByte for LockGuard<'a> {
     fn read_u8(&mut self) -> Result<Option<u8>, ()> {
         let mut buf = [0];
         match self.0.read(&mut buf) {

+ 2 - 2
src/header/stdio/printf.rs

@@ -2,10 +2,10 @@ use core::fmt::Write as CoreWrite;
 use core::{ptr, slice, str};
 
 use platform::types::*;
-use platform::{self, Write};
+use platform::{self, WriteByte};
 use va_list::VaList;
 
-pub unsafe fn printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) -> c_int {
+pub unsafe fn printf<W: WriteByte>(w: W, format: *const c_char, mut ap: VaList) -> c_int {
     let mut w = platform::CountingWriter::new(w);
 
     let format = slice::from_raw_parts(format as *const u8, usize::max_value());

+ 3 - 3
src/header/stdio/scanf.rs

@@ -1,7 +1,7 @@
 use alloc::String;
 use alloc::Vec;
 use platform::types::*;
-use platform::Read;
+use platform::ReadByte;
 use va_list::VaList;
 
 #[derive(PartialEq, Eq)]
@@ -27,7 +27,7 @@ unsafe fn next_byte(string: &mut *const c_char) -> Result<u8, c_int> {
     }
 }
 
-unsafe fn inner_scanf<R: Read>(
+unsafe fn inner_scanf<R: ReadByte>(
     mut r: R,
     mut format: *const c_char,
     mut ap: VaList,
@@ -420,7 +420,7 @@ unsafe fn inner_scanf<R: Read>(
     }
     Ok(matched)
 }
-pub unsafe fn scanf<R: Read>(r: R, format: *const c_char, ap: VaList) -> c_int {
+pub unsafe fn scanf<R: ReadByte>(r: R, format: *const c_char, ap: VaList) -> c_int {
     match inner_scanf(r, format, ap) {
         Ok(n) => n,
         Err(n) => n,

+ 3 - 3
src/header/time/strftime.rs

@@ -1,12 +1,12 @@
 use alloc::string::String;
 
 use platform::types::*;
-use platform::{self, Write};
+use platform::{self, WriteByte};
 
 use super::tm;
 
-pub unsafe fn strftime<W: Write>(w: &mut W, format: *const c_char, t: *const tm) -> size_t {
-    pub unsafe fn inner_strftime<W: Write>(
+pub unsafe fn strftime<W: WriteByte>(w: &mut W, format: *const c_char, t: *const tm) -> size_t {
+    pub unsafe fn inner_strftime<W: WriteByte>(
         w: &mut W,
         mut format: *const c_char,
         t: *const tm,

+ 11 - 11
src/platform/mod.rs

@@ -107,21 +107,21 @@ pub unsafe fn memcpy(s1: *mut c_void, s2: *const c_void, n: usize) -> *mut c_voi
     s1
 }
 
-pub trait Write: fmt::Write {
+pub trait WriteByte: fmt::Write {
     fn write_u8(&mut self, byte: u8) -> fmt::Result;
 }
 
-impl<'a, W: Write> Write for &'a mut W {
+impl<'a, W: WriteByte> WriteByte for &'a mut W {
     fn write_u8(&mut self, byte: u8) -> fmt::Result {
         (**self).write_u8(byte)
     }
 }
 
-pub trait Read {
+pub trait ReadByte {
     fn read_u8(&mut self) -> Result<Option<u8>, ()>;
 }
 
-impl<'a, R: Read> Read for &'a mut R {
+impl<'a, R: ReadByte> ReadByte for &'a mut R {
     fn read_u8(&mut self) -> Result<Option<u8>, ()> {
         (**self).read_u8()
     }
@@ -142,7 +142,7 @@ impl fmt::Write for FileWriter {
     }
 }
 
-impl Write for FileWriter {
+impl WriteByte for FileWriter {
     fn write_u8(&mut self, byte: u8) -> fmt::Result {
         self.write(&[byte]);
         Ok(())
@@ -157,7 +157,7 @@ impl FileReader {
     }
 }
 
-impl Read for FileReader {
+impl ReadByte for FileReader {
     fn read_u8(&mut self) -> Result<Option<u8>, ()> {
         let mut buf = [0];
         match self.read(&mut buf) {
@@ -194,7 +194,7 @@ impl fmt::Write for StringWriter {
     }
 }
 
-impl Write for StringWriter {
+impl WriteByte for StringWriter {
     fn write_u8(&mut self, byte: u8) -> fmt::Result {
         unsafe { self.write(&[byte]) };
         Ok(())
@@ -222,7 +222,7 @@ impl fmt::Write for UnsafeStringWriter {
     }
 }
 
-impl Write for UnsafeStringWriter {
+impl WriteByte for UnsafeStringWriter {
     fn write_u8(&mut self, byte: u8) -> fmt::Result {
         unsafe { self.write(&[byte]) };
         Ok(())
@@ -231,7 +231,7 @@ impl Write for UnsafeStringWriter {
 
 pub struct StringReader<'a>(pub &'a [u8]);
 
-impl<'a> Read for StringReader<'a> {
+impl<'a> ReadByte for StringReader<'a> {
     fn read_u8(&mut self) -> Result<Option<u8>, ()> {
         if self.0.is_empty() {
             Ok(None)
@@ -245,7 +245,7 @@ impl<'a> Read for StringReader<'a> {
 
 pub struct UnsafeStringReader(pub *const u8);
 
-impl Read for UnsafeStringReader {
+impl ReadByte for UnsafeStringReader {
     fn read_u8(&mut self) -> Result<Option<u8>, ()> {
         unsafe {
             if *self.0 == 0 {
@@ -277,7 +277,7 @@ impl<T: fmt::Write> fmt::Write for CountingWriter<T> {
         self.inner.write_str(s)
     }
 }
-impl<T: Write> Write for CountingWriter<T> {
+impl<T: WriteByte> WriteByte for CountingWriter<T> {
     fn write_u8(&mut self, byte: u8) -> fmt::Result {
         self.written += 1;
         self.inner.write_u8(byte)

+ 0 - 2
src/platform/pal/mod.rs

@@ -1,5 +1,3 @@
-use core::ptr;
-
 use super::types::*;
 use c_str::CStr;
 use header::dirent::dirent;