summaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
authorWez Furlong <wez@wezfurlong.org>2019-07-23 16:39:28 -0700
committerWez Furlong <wez@wezfurlong.org>2019-07-29 08:55:06 -0700
commit18dc0f59e0b29c50da525dbe85d36fb5cb0ecf62 (patch)
tree5f424e77c3bc053a39aea417fea6fe75b963f1d9 /src/util.rs
parent78d2e3d9dbf1530cdf4bc152b91f0ddd7ce4895b (diff)
downloadssh2-rs-18dc0f59e0b29c50da525dbe85d36fb5cb0ecf62.zip
cargo fmt
No functional changes, just formatting
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/util.rs b/src/util.rs
index 414bbb2..ac6c722 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,7 +1,7 @@
use std::borrow::Cow;
use std::path::Path;
-use {raw, Session, Error};
+use {raw, Error, Session};
#[doc(hidden)]
pub trait Binding: Sized {
@@ -18,8 +18,7 @@ pub trait SessionBinding<'sess>: Sized {
unsafe fn from_raw(sess: &'sess Session, raw: *mut Self::Raw) -> Self;
fn raw(&self) -> *mut Self::Raw;
- unsafe fn from_raw_opt(sess: &'sess Session, raw: *mut Self::Raw)
- -> Result<Self, Error> {
+ unsafe fn from_raw_opt(sess: &'sess Session, raw: *mut Self::Raw) -> Result<Self, Error> {
if raw.is_null() {
Err(Error::last_error(sess).unwrap_or_else(Error::unknown))
} else {
@@ -30,8 +29,8 @@ pub trait SessionBinding<'sess>: Sized {
#[cfg(unix)]
pub fn path2bytes(p: &Path) -> Result<Cow<[u8]>, Error> {
- use std::os::unix::prelude::*;
use std::ffi::OsStr;
+ use std::os::unix::prelude::*;
let s: &OsStr = p.as_ref();
check(Cow::Borrowed(s.as_bytes()))
}
@@ -39,8 +38,12 @@ pub fn path2bytes(p: &Path) -> Result<Cow<[u8]>, Error> {
pub fn path2bytes(p: &Path) -> Result<Cow<[u8]>, Error> {
p.to_str()
.map(|s| s.as_bytes())
- .ok_or_else(|| Error::new(raw::LIBSSH2_ERROR_INVAL,
- "only unicode paths on windows may be used"))
+ .ok_or_else(|| {
+ Error::new(
+ raw::LIBSSH2_ERROR_INVAL,
+ "only unicode paths on windows may be used",
+ )
+ })
.map(|bytes| {
if bytes.contains(&b'\\') {
// Normalize to Unix-style path separators
@@ -60,8 +63,10 @@ pub fn path2bytes(p: &Path) -> Result<Cow<[u8]>, Error> {
fn check(b: Cow<[u8]>) -> Result<Cow<[u8]>, Error> {
if b.iter().any(|b| *b == 0) {
- Err(Error::new(raw::LIBSSH2_ERROR_INVAL,
- "path provided contains a 0 byte"))
+ Err(Error::new(
+ raw::LIBSSH2_ERROR_INVAL,
+ "path provided contains a 0 byte",
+ ))
} else {
Ok(b)
}