diff options
| author | NODA, Kai <nodakai@gmail.com> | 2014-11-06 00:40:08 +0800 |
|---|---|---|
| committer | NODA, Kai <nodakai@gmail.com> | 2016-03-27 05:19:10 +0800 |
| commit | bf94aefd5aa9d9cbf24d5dd82280186777669eb1 (patch) | |
| tree | ca0ce7e8ea244737005837b3c51fe7b3c89ddc67 /src/libstd/sys | |
| parent | 346d0d5175e7b236a7e3f41fd992afc61f148442 (diff) | |
| download | rust-bf94aefd5aa9d9cbf24d5dd82280186777669eb1.tar.gz rust-bf94aefd5aa9d9cbf24d5dd82280186777669eb1.zip | |
libstd/sys/*/net: very minor clean up of cvt*() utility functions.
Signed-off-by: NODA, Kai <nodakai@gmail.com>
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/windows/net.rs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs index ab2d969fe0a..b05dcf42a33 100644 --- a/src/libstd/sys/windows/net.rs +++ b/src/libstd/sys/windows/net.rs @@ -61,27 +61,28 @@ fn last_error() -> io::Error { } /// Checks if the signed integer is the Windows constant `SOCKET_ERROR` (-1) -/// and if so, returns the last error from the Windows socket interface. . This +/// and if so, returns the last error from the Windows socket interface. This /// function must be called before another call to the socket API is made. -pub fn cvt<T: One + Neg<Output=T> + PartialEq>(t: T) -> io::Result<T> { - let one: T = T::one(); - if t == -one { +pub fn cvt<T: One + PartialEq + Neg<Output=T>>(t: T) -> io::Result<T> { + if t == -T::one() { Err(last_error()) } else { Ok(t) } } -/// Provides the functionality of `cvt` for the return values of `getaddrinfo` -/// and similar, meaning that they return an error if the return value is 0. +/// A variant of `cvt` for `getaddrinfo` which return 0 for a success. pub fn cvt_gai(err: c_int) -> io::Result<()> { - if err == 0 { return Ok(()) } - cvt(err).map(|_| ()) + if err == 0 { + Ok(()) + } else { + Err(last_error()) + } } -/// Provides the functionality of `cvt` for a closure. +/// Just to provide the same interface as sys/unix/net.rs pub fn cvt_r<T, F>(mut f: F) -> io::Result<T> - where F: FnMut() -> T, T: One + Neg<Output=T> + PartialEq + where T: One + PartialEq + Neg<Output=T>, F: FnMut() -> T { cvt(f()) } |
