better support Path and str in parse_file args

This commit is contained in:
Raamakrishnan 2020-02-07 21:35:09 +05:30
parent bc536c6c15
commit abda8754a6
3 changed files with 7 additions and 4 deletions

View file

@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Changed
- Argument to `parse_file` is changed to `AsRef<Path>`
## [0.1.0] - 2020-02-02
### Added

View file

@ -4,7 +4,7 @@ A library in Rust to parse a Verilog Filelist and return
a list of files, include directories and defines.
Environment variables represented with paranthesis or
curly braces (i.e. $() or ${}) will be automatically
curly braces (i.e. `$()` or `${}`) will be automatically
substituted.
# Example

View file

@ -2,7 +2,7 @@ use regex::Regex;
use std::collections::HashMap;
use std::error::Error;
use std::fs;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use crate::line_parser;
use crate::line_parser::LineType;
@ -49,15 +49,16 @@ impl Filelist {
/// Environment variables represented with paranthesis or
/// curly braces (i.e. `$()` or `${}`) will be automatically
/// substituted.
///
/// # Arguments
///
/// * `path` - A string slice that is the path to the filelist
/// * `path` - The path to the filelist
///
/// # Errors
///
/// Returns an error if the filelist in `path` cannot be read. Also returns
/// error if any of the nested filelists cannot be read.
pub fn parse_file(path: &str) -> Result<Filelist, Box<dyn Error>> {
pub fn parse_file(path: impl AsRef<Path>) -> Result<Filelist, Box<dyn Error>> {
let contents = fs::read_to_string(path)?;
let mut filelist = Filelist::new();