Cleanup & reformat

This commit is contained in:
Konstantin Gribov
2021-01-26 21:19:00 +03:00
parent 7c6bf2ce55
commit cbeefdd4d8
2 changed files with 19 additions and 25 deletions

View File

@@ -23,12 +23,6 @@
//! Primary entrypoint is [`SmbClient`](struct.SmbClient.html) struct. //! Primary entrypoint is [`SmbClient`](struct.SmbClient.html) struct.
//! //!
//! Files are represented by [`SmbFile`](struct.SmbFile.html). //! Files are represented by [`SmbFile`](struct.SmbFile.html).
//!
//! Basic example:
//! ```rust
//! fn load
//! # fn main() {}
//! ```
#[macro_use] #[macro_use]
extern crate log; extern crate log;

View File

@@ -70,7 +70,7 @@ const SMBC_TRUE: smbc_bool = 1;
/// let auth = move |host: &str, share: &str| { /// let auth = move |host: &str, share: &str| {
/// (Cow::Borrowed("WORKGROUP"), Cow::Borrowed("test"), Cow::Borrowed(password_ref)) /// (Cow::Borrowed("WORKGROUP"), Cow::Borrowed("test"), Cow::Borrowed(password_ref))
/// }; /// };
/// let client = try!(smbc::SmbClient::new(&auth)); /// let client = smbc::SmbClient::new(&auth)?;
/// ///
/// # Ok(()) /// # Ok(())
/// # } /// # }
@@ -103,7 +103,7 @@ pub struct SmbClient<'a> {
/// # /// #
/// fn get_content(file: &mut smbc::SmbFile) -> smbc::Result<String> { /// fn get_content(file: &mut smbc::SmbFile) -> smbc::Result<String> {
/// let mut buffer = String::new(); /// let mut buffer = String::new();
/// try!(file.read_to_string(&mut buffer)); /// file.read_to_string(&mut buffer)?;
/// Ok(buffer) /// Ok(buffer)
/// } /// }
/// ///
@@ -113,8 +113,8 @@ pub struct SmbClient<'a> {
/// # let auth = move |host: &str, share: &str| { /// # let auth = move |host: &str, share: &str| {
/// # (Cow::Borrowed("WORKGROUP"), Cow::Borrowed("test"), Cow::Borrowed(password)) /// # (Cow::Borrowed("WORKGROUP"), Cow::Borrowed("test"), Cow::Borrowed(password))
/// # }; /// # };
/// let client = try!(smbc::SmbClient::new(&auth)); /// let client = smbc::SmbClient::new(&auth)?;
/// let mut file = try!(client.open("smb://127.0.0.1/share/path/to/file")); /// let mut file = client.open("smb://127.0.0.1/share/path/to/file")?;
/// println!("dumped file:\n\n{}", try!(get_content(&mut file))); /// println!("dumped file:\n\n{}", try!(get_content(&mut file)));
/// Ok(()) /// Ok(())
/// } /// }
@@ -144,7 +144,7 @@ impl<'a> SmbClient<'a> {
where F: for<'b> Fn(&'b str, &'b str) -> (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>) { where F: for<'b> Fn(&'b str, &'b str) -> (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>) {
let mut smbc = SmbClient { let mut smbc = SmbClient {
ctx: ptr::null_mut(), ctx: ptr::null_mut(),
auth_fn: auth_fn, auth_fn,
}; };
unsafe { unsafe {
@@ -167,15 +167,15 @@ impl<'a> SmbClient<'a> {
/// Auth wrapper passed to `SMBCCTX` to authenticate requests to SMB servers. /// Auth wrapper passed to `SMBCCTX` to authenticate requests to SMB servers.
extern "C" fn auth_wrapper<F: 'a>(ctx: *mut SMBCCTX, extern "C" fn auth_wrapper<F: 'a>(ctx: *mut SMBCCTX,
srv: *const c_char, srv: *const c_char,
shr: *const c_char, shr: *const c_char,
wg: *mut c_char, wg: *mut c_char,
wglen: c_int, wglen: c_int,
un: *mut c_char, un: *mut c_char,
unlen: c_int, unlen: c_int,
pw: *mut c_char, pw: *mut c_char,
pwlen: c_int) pwlen: c_int)
-> () -> ()
where F: for<'b> Fn(&'b str, &'b str) -> (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>) { where F: for<'b> Fn(&'b str, &'b str) -> (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>) {
unsafe { unsafe {
let srv = cstr(srv); let srv = cstr(srv);
@@ -209,18 +209,18 @@ impl<'a> SmbClient<'a> {
let open_fn = try_ufn!(smbc_getFunctionOpen <- self); let open_fn = try_ufn!(smbc_getFunctionOpen <- self);
let path = cstring(path)?; let path = cstring(path)?;
trace!(target: "smbc", "opening {:?} with {:?}", path, open_fn); trace!(target: "smbc", "opening {:?}", path);
let fd = result_from_ptr_mut(open_fn(self.ctx, let fd = result_from_ptr_mut(open_fn(self.ctx,
path.as_ptr(), path.as_ptr(),
options.to_flags()?, options.to_flags()?,
options.mode))?; options.mode))?;
if (fd as i64) < 0 { if (fd as i64) < 0 {
trace!(target: "smbc", "neg fd"); trace!(target: "smbc", "neg fd");
} }
Ok(SmbFile { Ok(SmbFile {
smbc: &self, smbc: &self,
fd: fd, fd,
}) })
} }