Skip to content

Run rustfmt on lib.rs and ignore .idea #1659

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 1 commit 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax: glob
Cargo.lock
target
.idea
*.diff
*.rej
*.orig
Expand Down
69 changes: 41 additions & 28 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
#![deny(missing_copy_implementations)]
#![deny(missing_debug_implementations)]
#![warn(missing_docs)]

#![cfg_attr(docsrs, feature(doc_cfg))]

// Re-exported external crates
pub use libc;

// Private internal modules
#[macro_use] mod macros;
#[macro_use]
mod macros;

// Public crates
#[cfg(not(target_os = "redox"))]
Expand Down Expand Up @@ -99,25 +99,24 @@ feature! {
#[deny(missing_docs)]
pub mod net;
}
#[cfg(any(target_os = "android",
target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "linux"))]
feature! {
#![feature = "kmod"]
#[allow(missing_docs)]
pub mod kmod;
}
#[cfg(any(target_os = "android",
target_os = "freebsd",
target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
feature! {
#![feature = "mount"]
pub mod mount;
}
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "fushsia",
target_os = "linux",
target_os = "netbsd"))]
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fushsia",
target_os = "linux",
target_os = "netbsd"
))]
feature! {
#![feature = "mqueue"]
#[allow(missing_docs)]
Expand Down Expand Up @@ -145,8 +144,7 @@ feature! {
}
// This can be implemented for other platforms as soon as libc
// provides bindings for them.
#[cfg(all(target_os = "linux",
any(target_arch = "x86", target_arch = "x86_64")))]
#[cfg(all(target_os = "linux", any(target_arch = "x86", target_arch = "x86_64")))]
feature! {
#![feature = "ucontext"]
#[allow(missing_docs)]
Expand All @@ -163,10 +161,10 @@ pub mod unistd;

use libc::PATH_MAX;

use std::result;
use std::ffi::{CStr, OsStr};
use std::os::unix::ffi::OsStrExt;
use std::path::{Path, PathBuf};
use std::result;

use errno::Errno;

Expand Down Expand Up @@ -197,7 +195,8 @@ pub trait NixPath {
///
/// Mostly used internally by Nix.
fn with_nix_path<T, F>(&self, f: F) -> Result<T>
where F: FnOnce(&CStr) -> T;
where
F: FnOnce(&CStr) -> T;
}

impl NixPath for str {
Expand All @@ -210,9 +209,11 @@ impl NixPath for str {
}

fn with_nix_path<T, F>(&self, f: F) -> Result<T>
where F: FnOnce(&CStr) -> T {
OsStr::new(self).with_nix_path(f)
}
where
F: FnOnce(&CStr) -> T,
{
OsStr::new(self).with_nix_path(f)
}
}

impl NixPath for OsStr {
Expand All @@ -225,9 +226,11 @@ impl NixPath for OsStr {
}

fn with_nix_path<T, F>(&self, f: F) -> Result<T>
where F: FnOnce(&CStr) -> T {
self.as_bytes().with_nix_path(f)
}
where
F: FnOnce(&CStr) -> T,
{
self.as_bytes().with_nix_path(f)
}
}

impl NixPath for CStr {
Expand All @@ -240,10 +243,12 @@ impl NixPath for CStr {
}

fn with_nix_path<T, F>(&self, f: F) -> Result<T>
where F: FnOnce(&CStr) -> T {
where
F: FnOnce(&CStr) -> T,
{
// Equivalence with the [u8] impl.
if self.len() >= PATH_MAX as usize {
return Err(Errno::ENAMETOOLONG)
return Err(Errno::ENAMETOOLONG);
}

Ok(f(self))
Expand All @@ -260,11 +265,13 @@ impl NixPath for [u8] {
}

fn with_nix_path<T, F>(&self, f: F) -> Result<T>
where F: FnOnce(&CStr) -> T {
where
F: FnOnce(&CStr) -> T,
{
let mut buf = [0u8; PATH_MAX as usize];

if self.len() >= PATH_MAX as usize {
return Err(Errno::ENAMETOOLONG)
return Err(Errno::ENAMETOOLONG);
}

buf[..self.len()].copy_from_slice(self);
Expand All @@ -284,7 +291,10 @@ impl NixPath for Path {
NixPath::len(self.as_os_str())
}

fn with_nix_path<T, F>(&self, f: F) -> Result<T> where F: FnOnce(&CStr) -> T {
fn with_nix_path<T, F>(&self, f: F) -> Result<T>
where
F: FnOnce(&CStr) -> T,
{
self.as_os_str().with_nix_path(f)
}
}
Expand All @@ -298,7 +308,10 @@ impl NixPath for PathBuf {
NixPath::len(self.as_os_str())
}

fn with_nix_path<T, F>(&self, f: F) -> Result<T> where F: FnOnce(&CStr) -> T {
fn with_nix_path<T, F>(&self, f: F) -> Result<T>
where
F: FnOnce(&CStr) -> T,
{
self.as_os_str().with_nix_path(f)
}
}