Browse Source

add `write` functions to write to the host's stdout

Jorge Aparicio 8 years ago
parent
commit
0524b9528e
4 changed files with 30 additions and 8 deletions
  1. 17 0
      CHANGELOG.md
  2. 10 4
      src/io.rs
  3. 1 2
      src/lib.rs
  4. 2 2
      src/macros.rs

+ 17 - 0
CHANGELOG.md

@@ -0,0 +1,17 @@
+# Change Log
+
+All notable changes to this project will be documented in this file.
+This project adheres to [Semantic Versioning](http://semver.org/).
+
+## [Unreleased]
+
+### Added
+
+- Expose a family of `write` functions to write to the host's stdout without
+  going through the `hprint!` macros.
+
+## v0.1.0 - 2017-01-22
+
+- Initial release
+
+[Unreleased]: https://github.com/japaric/trust/compare/v0.1.0...HEAD

+ 10 - 4
src/io.rs

@@ -35,11 +35,17 @@ impl Write for Stdout {
     }
 }
 
-pub fn _write_str(s: &str) {
-    Stdout.write_str(s).ok();
+/// Write a `buffer` to the host's stdout
+pub fn write(buffer: &[u8]) {
+    Stdout.write_all(buffer)
 }
 
-pub fn _write_fmt(args: fmt::Arguments) {
-
+/// Write `fmt::Arguments` to the host's stdout
+pub fn write_fmt(args: fmt::Arguments) {
     Stdout.write_fmt(args).ok();
 }
+
+/// Write a `string` to the host's stdout
+pub fn write_str(string: &str) {
+    Stdout.write_all(string.as_bytes())
+}

+ 1 - 2
src/lib.rs

@@ -107,9 +107,8 @@
 
 #[macro_use]
 mod macros;
-#[doc(hidden)]
-pub mod io;
 
+pub mod io;
 pub mod nr;
 
 /// Performs a semihosting operation

+ 2 - 2
src/macros.rs

@@ -19,8 +19,8 @@ macro_rules! syscall {
 /// Macro for printing to the **host's** standard output
 #[macro_export]
 macro_rules! hprint {
-    ($s:expr) => ($crate::io::_write_str($s));
-    ($($arg:tt)*) => ($crate::io::_write_fmt(format_args!($($arg)*)));
+    ($s:expr) => ($crate::io::write_str($s));
+    ($($arg:tt)*) => ($crate::io::write_fmt(format_args!($($arg)*)));
 }
 
 /// Macro for printing to the **host's** standard output, with a newline.