Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .write_str() to std::rt::io, and port to rt::io for libstd Repr and ToStr #8089

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/libstd/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ A quick summary:
Implementations of the following traits:

* `FromStr`
* `ToStr`
* `Not`
* `Ord`
* `TotalOrd`
Expand All @@ -39,7 +38,6 @@ Finally, some inquries into the nature of truth: `is_true` and `is_false`.

use option::{None, Option, Some};
use from_str::FromStr;
use to_str::ToStr;

#[cfg(not(test))] use cmp::{Eq, Ord, TotalOrd, Ordering};
#[cfg(not(test))] use ops::Not;
Expand Down Expand Up @@ -202,28 +200,6 @@ impl FromStr for bool {
}
}

/**
* Convert a `bool` to a `str`.
*
* # Examples
*
* ~~~ {.rust}
* rusti> true.to_str()
* "true"
* ~~~
*
* ~~~ {.rust}
* rusti> false.to_str()
* "false"
* ~~~
*/
impl ToStr for bool {
#[inline]
fn to_str(&self) -> ~str {
if *self { ~"true" } else { ~"false" }
}
}

/**
* Iterates over all truth values, passing them to the given block.
*
Expand Down
10 changes: 7 additions & 3 deletions src/libstd/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,19 @@ pub fn console_off() {
pub fn log_type<T>(level: u32, object: &T) {
use cast;
use container::Container;
use io;
use rt::io::Decorator;
use rt::io::mem::MemWriter;
use libc;
use repr;
use rt;
use str;
use util;
use vec;

let bytes = do io::with_bytes_writer |writer| {
repr::write_repr(writer, object);
let bytes = {
let wr = @mut MemWriter::new();
repr::write_repr(wr, object);
util::replace(wr, MemWriter::new()).inner()
};

match rt::context() {
Expand Down
8 changes: 8 additions & 0 deletions src/libstd/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ macro_rules! int_module (($T:ty, $bits:expr) => (mod generated {
use num::{ToStrRadix, FromStrRadix};
use num::{Zero, One, strconv};
use prelude::*;
use rt::io::StringWriter;
use str;

pub use cmp::{min, max};
Expand Down Expand Up @@ -557,6 +558,13 @@ impl ToStr for $T {
fn to_str(&self) -> ~str {
to_str(*self)
}

#[inline]
fn to_str_writer<W: StringWriter>(&self, w: &mut W) {
do strconv::int_to_str_bytes_common(*self, 10u, strconv::SignNeg) |c| {
w.write_char(c as char)
}
}
}

impl ToStrRadix for $T {
Expand Down
8 changes: 8 additions & 0 deletions src/libstd/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use num::BitCount;
use num::{ToStrRadix, FromStrRadix};
use num::{Zero, One, strconv};
use prelude::*;
use rt::io::StringWriter;
use str;

pub use cmp::{min, max};
Expand Down Expand Up @@ -411,6 +412,13 @@ impl ToStr for $T {
fn to_str(&self) -> ~str {
to_str(*self)
}

#[inline]
fn to_str_writer<W: StringWriter>(&self, w: &mut W) {
do strconv::int_to_str_bytes_common(*self, 10u, strconv::SignNeg) |c| {
w.write_char(c as char)
}
}
}

impl ToStrRadix for $T {
Expand Down
Loading