Implement RFC 1014
Closes #25977 The various `stdfoo_raw` methods in std::io now return `io::Result`s, since they may not exist on Windows. They will always return `Ok` on Unix-like platforms. [breaking-change]
This commit is contained in:
parent
2228ce10c6
commit
a7bbd7da4e
7 changed files with 161 additions and 33 deletions
|
|
@ -77,11 +77,13 @@ fn write(out: &Output, data: &[u8]) -> io::Result<usize> {
|
|||
}
|
||||
|
||||
impl Stdin {
|
||||
pub fn new() -> Stdin {
|
||||
Stdin {
|
||||
handle: get(c::STD_INPUT_HANDLE).unwrap(),
|
||||
utf8: Mutex::new(Cursor::new(Vec::new())),
|
||||
}
|
||||
pub fn new() -> io::Result<Stdin> {
|
||||
get(c::STD_INPUT_HANDLE).map(|handle| {
|
||||
Stdin {
|
||||
handle: handle,
|
||||
utf8: Mutex::new(Cursor::new(Vec::new())),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
|
|
@ -116,8 +118,8 @@ impl Stdin {
|
|||
}
|
||||
|
||||
impl Stdout {
|
||||
pub fn new() -> Stdout {
|
||||
Stdout(get(c::STD_OUTPUT_HANDLE).unwrap())
|
||||
pub fn new() -> io::Result<Stdout> {
|
||||
get(c::STD_OUTPUT_HANDLE).map(Stdout)
|
||||
}
|
||||
|
||||
pub fn write(&self, data: &[u8]) -> io::Result<usize> {
|
||||
|
|
@ -126,8 +128,8 @@ impl Stdout {
|
|||
}
|
||||
|
||||
impl Stderr {
|
||||
pub fn new() -> Stderr {
|
||||
Stderr(get(c::STD_ERROR_HANDLE).unwrap())
|
||||
pub fn new() -> io::Result<Stderr> {
|
||||
get(c::STD_ERROR_HANDLE).map(Stderr)
|
||||
}
|
||||
|
||||
pub fn write(&self, data: &[u8]) -> io::Result<usize> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue