Update few more APIs to use AsRef<Path>
This makes few more final APIs that work with files consistent with the rest. Fixes #280.
This commit is contained in:
parent
2932819567
commit
bc517fd899
@ -243,8 +243,8 @@ impl Builder {
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn with_src(mut self, src: &path::Path) -> Builder {
|
||||
self.srcs.push(src.to_owned());
|
||||
pub fn with_src<P: AsRef<path::Path>>(mut self, src: P) -> Builder {
|
||||
self.srcs.push(src.as_ref().to_owned());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -610,8 +610,8 @@ impl Default for Config {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_file(file_name: &str) -> Result<Config, String> {
|
||||
fn read(file_name: &str) -> io::Result<String> {
|
||||
pub fn from_file<P: AsRef<Path>>(file_name: P) -> Result<Config, String> {
|
||||
fn read(file_name: &Path) -> io::Result<String> {
|
||||
let file = File::open(file_name)?;
|
||||
let mut reader = BufReader::new(&file);
|
||||
let mut contents = String::new();
|
||||
@ -619,7 +619,7 @@ impl Config {
|
||||
Ok(contents)
|
||||
}
|
||||
|
||||
let config_text = read(file_name).unwrap();
|
||||
let config_text = read(file_name.as_ref()).unwrap();
|
||||
|
||||
match toml::from_str::<Config>(&config_text) {
|
||||
Ok(x) => Ok(x),
|
||||
@ -627,11 +627,11 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_root_or_default(root: &Path) -> Config {
|
||||
let c = root.join("cbindgen.toml");
|
||||
pub fn from_root_or_default<P: AsRef<Path>>(root: P) -> Config {
|
||||
let c = root.as_ref().join("cbindgen.toml");
|
||||
|
||||
if c.exists() {
|
||||
Config::from_file(c.to_str().unwrap()).unwrap()
|
||||
Config::from_file(c).unwrap()
|
||||
} else {
|
||||
Config::default()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user