Commit 3b848699 authored by Cyril Plisko's avatar Cyril Plisko 🤔

Rust 2018

parent c5405433
......@@ -8,6 +8,7 @@ name = "pager"
readme = "README.md"
repository = "https://gitlab.com/imp/pager-rs.git"
version = "0.15.0" # remember to update html_root_url
edition = "2018"
categories = ["command-line-interface", "text-processing"]
[badges]
......
......@@ -77,13 +77,16 @@
//! reflect the fact that no Pager is active.
#![doc(html_root_url = "https://docs.rs/pager/0.15.0")]
#![cfg_attr(
all(feature = "cargo-clippy", feature = "pedantic"),
warn(clippy_pedantic)
)]
extern crate errno;
extern crate libc;
#![cfg_attr(feature = "pedantic", warn(clippy::pedantic))]
#![warn(clippy::use_self)]
#![warn(deprecated_in_future)]
#![warn(future_incompatible)]
#![warn(unreachable_pub)]
#![warn(missing_debug_implementations)]
#![warn(rust_2018_compatibility)]
#![warn(rust_2018_idioms)]
#![warn(unused)]
#![deny(warnings)]
mod utils;
......@@ -248,21 +251,21 @@ mod tests {
fn new<S: AsRef<OsStr>>(env: S) -> Self {
let env = env.as_ref().into();
if let Some(value) = env::var_os(&env) {
PagerEnv::Reinstate(env, value)
Self::Reinstate(env, value)
} else {
PagerEnv::Remove(env)
Self::Remove(env)
}
}
fn set<S: AsRef<OsStr>>(&self, value: S) {
match self {
PagerEnv::Reinstate(env, _) | PagerEnv::Remove(env) => env::set_var(env, value),
Self::Reinstate(env, _) | Self::Remove(env) => env::set_var(env, value),
}
}
fn remove(&self) {
match self {
PagerEnv::Reinstate(env, _) | PagerEnv::Remove(env) => env::remove_var(env),
Self::Reinstate(env, _) | Self::Remove(env) => env::remove_var(env),
}
}
}
......@@ -270,8 +273,8 @@ mod tests {
impl Drop for PagerEnv {
fn drop(&mut self) {
match self {
PagerEnv::Reinstate(env, value) => env::set_var(env, value),
PagerEnv::Remove(env) => env::remove_var(env),
Self::Reinstate(env, value) => env::set_var(env, value),
Self::Remove(env) => env::remove_var(env),
}
}
}
......
......@@ -2,9 +2,6 @@ use std::ffi::{CString, OsString};
use std::os::unix::ffi::OsStringExt;
use std::ptr;
use errno;
use libc;
fn osstring2cstring(s: OsString) -> CString {
unsafe { CString::from_vec_unchecked(s.into_vec()) }
}
......@@ -17,11 +14,11 @@ fn split_string(s: &OsString) -> Vec<OsString> {
}
// Helper wrappers around libc::* API
pub fn fork() -> libc::pid_t {
pub(crate) fn fork() -> libc::pid_t {
unsafe { libc::fork() }
}
pub fn execvp(cmd: &OsString) {
pub(crate) fn execvp(cmd: &OsString) {
let cstrings = split_string(cmd)
.into_iter()
.map(osstring2cstring)
......@@ -32,7 +29,7 @@ pub fn execvp(cmd: &OsString) {
unsafe { libc::execvp(args[0], args.as_ptr()) };
}
pub fn execvpe(cmd: &OsString, envs: &[OsString]) {
pub(crate) fn execvpe(cmd: &OsString, envs: &[OsString]) {
let cstrings = split_string(cmd)
.into_iter()
.map(osstring2cstring)
......@@ -56,21 +53,20 @@ pub fn execvpe(cmd: &OsString, envs: &[OsString]) {
unsafe { libc::execvpe(args[0], args.as_ptr(), envs.as_ptr()) };
}
pub fn dup2(fd1: i32, fd2: i32) {
pub(crate) fn dup2(fd1: i32, fd2: i32) {
assert!(unsafe { libc::dup2(fd1, fd2) } > -1);
}
pub fn close(fd: i32) {
pub(crate) fn close(fd: i32) {
assert_eq!(unsafe { libc::close(fd) }, 0);
}
pub fn pipe() -> (i32, i32) {
pub(crate) fn pipe() -> (i32, i32) {
let mut fds = [0; 2];
assert_eq!(unsafe { libc::pipe(fds.as_mut_ptr()) }, 0);
(fds[0], fds[1])
}
pub fn isatty(fd: i32) -> bool {
let isatty = unsafe { libc::isatty(fd) };
isatty != 0
pub(crate) fn isatty(fd: i32) -> bool {
unsafe { libc::isatty(fd) != 0 }
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment