configparser: upgrade crate to rust edition 2018

Summary: As requested in D14380687.

Differential Revision: D14393014

fbshipit-source-id: 365c713b6f5a106cef0b945e63f224b7651d0e8f
This commit is contained in:
Stefan Filip 2019-03-11 15:24:34 -07:00 committed by Facebook Github Bot
parent 3f33e9f3e9
commit 2eb3c24956
8 changed files with 32 additions and 45 deletions

View File

@ -1,6 +1,7 @@
[package]
name = "configparser"
version = "0.1.0"
edition = "2018"
[dependencies]
bytes = "0.4.10"

View File

@ -3,14 +3,12 @@
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
extern crate bytes;
extern crate configparser;
extern crate minibench;
use std::io::Write;
use bytes::Bytes;
use configparser::config::ConfigSet;
use minibench::{bench, elapsed};
use std::io::Write;
use configparser::config::ConfigSet;
fn main() {
bench("parse 645KB file", || {

View File

@ -4,17 +4,18 @@
// GNU General Public License version 2 or any later version.
//! This module exports some symbols to allow calling the config parser from C/C++
use bytes::Bytes;
use std::ffi::{CStr, OsStr};
use std::os::raw::c_char;
use std::path::Path;
use std::ptr;
use std::slice;
use config::{ConfigSet, Options};
use error::Error;
use hg::ConfigSetHgExt;
use hg::OptionsHgExt;
use bytes::Bytes;
use crate::config::{ConfigSet, Options};
use crate::error::Error;
use crate::hg::ConfigSetHgExt;
use crate::hg::OptionsHgExt;
/// Create and return a new, empty ConfigSet
#[no_mangle]

View File

@ -3,12 +3,6 @@
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
use bytes::Bytes;
use error::Error;
use indexmap::IndexMap;
use parser::{ConfigParser, Rule};
use pest::{self, Parser, Span};
use shellexpand;
use std::borrow::Cow;
use std::collections::HashSet;
use std::convert::AsRef;
@ -19,6 +13,14 @@ use std::path::{Path, PathBuf};
use std::str;
use std::sync::Arc;
use bytes::Bytes;
use indexmap::IndexMap;
use pest::{self, Parser, Span};
use shellexpand;
use crate::error::Error;
use crate::parser::{ConfigParser, Rule};
type Pair<'a> = pest::iterators::Pair<'a, Rule>;
/// Collection of config sections loaded from various sources.

View File

@ -7,6 +7,8 @@ use std::io;
use std::path::PathBuf;
use std::str;
use failure::Fail;
/// The error type for parsing config files.
#[derive(Fail, Debug)]
pub enum Error {

View File

@ -36,10 +36,6 @@ def expand_parser(pest):
with open(os.path.join(tmp_root, "src", "lib.rs"), "w") as f:
f.write(
"""
extern crate pest;
#[macro_use]
extern crate pest_derive;
#[derive(Parser)]
#[grammar = "spec.pest"]
pub(crate) struct ConfigParser;

View File

@ -5,16 +5,18 @@
//! Mercurial-specific config postprocessing
use bytes::Bytes;
use config::{expand_path, ConfigSet, Options};
use dirs;
use error::Error;
use std::cmp::Eq;
use std::collections::{HashMap, HashSet};
use std::env;
use std::hash::Hash;
use std::path::Path;
use bytes::Bytes;
use dirs;
use crate::config::{expand_path, ConfigSet, Options};
use crate::error::Error;
const HGPLAIN: &str = "HGPLAIN";
const HGPLAINEXCEPT: &str = "HGPLAINEXCEPT";
const HGRCPATH: &str = "HGRCPATH";
@ -394,14 +396,14 @@ fn parse_list_internal(value: &[u8]) -> Vec<Vec<u8>> {
continue;
} else if branch == 2 {
// last.ends_with(b"\\")
let mut last = parts.last_mut().unwrap();
let last = parts.last_mut().unwrap();
last.pop();
last.push(value[offset]);
offset += 1;
continue;
}
}
let mut last = parts.last_mut().unwrap();
let last = parts.last_mut().unwrap();
last.push(value[offset]);
offset += 1;
}
@ -507,9 +509,11 @@ fn parse_list_internal(value: &[u8]) -> Vec<Vec<u8>> {
#[cfg(test)]
mod tests {
use super::*;
use config::tests::write_file;
use tempdir::TempDir;
use crate::config::tests::write_file;
#[test]
fn test_basic_hgplain() {
env::set_var(HGPLAIN, "1");

View File

@ -64,27 +64,10 @@
//! line3
//! ```
extern crate bytes;
extern crate dirs;
extern crate failure;
#[macro_use]
extern crate failure_derive;
extern crate indexmap;
extern crate pest;
extern crate shellexpand;
pub mod c_api;
pub mod config;
pub mod error;
pub mod hg;
pub mod parser;
pub mod c_api;
pub use error::Error;
#[cfg(test)]
extern crate tempdir;