Skip to content

add puts() to libstd and the prelude #9361

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

Closed
wants to merge 2 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
16 changes: 16 additions & 0 deletions src/libstd/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,22 @@ pub fn println(s: &str) {
stdout().write_line(s);
}

/**
* Prints every object that implements the ToStr trait to standard output, followed by a newline.
*
* It works like, eg, ruby's puts.
*
* # Example
*
* ~~~ {.rust}
* // puts is imported into the prelude, and so is always available.
* puts(3u);
* ~~~
*/
pub fn puts<T: ToStr>(input: T) {
stdout().write_line(input.to_str());
}

pub struct BytesWriter {
bytes: @mut ~[u8],
pos: @mut uint,
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub use option::{Option, Some, None};
pub use result::{Result, Ok, Err};

// Reexported functions
pub use io::{print, println};
pub use io::{print, println, puts};
pub use iter::range;
pub use from_str::from_str;

Expand Down