From 4061408e5c4f3d8848407dac5646152e60796363 Mon Sep 17 00:00:00 2001 From: Raamakrishnan Date: Fri, 31 Jan 2020 21:35:14 +0530 Subject: [PATCH] Changing files and incdirs to PathBuf from String --- src/file_parser.rs | 9 +++++---- tests/integration_tests.rs | 13 ++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/file_parser.rs b/src/file_parser.rs index 8dd8afc..895274e 100644 --- a/src/file_parser.rs +++ b/src/file_parser.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::error::Error; use std::fs; +use std::path::PathBuf; use regex::Regex; use crate::line_parser; @@ -8,8 +9,8 @@ use crate::line_parser::LineType; #[derive(PartialEq, Debug, Default)] pub struct Filelist { - pub files: Vec, - pub incdirs: Vec, + pub files: Vec, + pub incdirs: Vec, pub defines: HashMap>, pub comments_present: bool, } @@ -40,7 +41,7 @@ pub fn parse_file(path: &str) -> Result> { for line in contents.lines() { let line = replace_env_vars(&line); match line_parser::parse_line(&line) { - LineType::File(file) => filelist.files.push(file.to_string()), + LineType::File(file) => filelist.files.push(PathBuf::from(file)), LineType::Define(define_map) => { for (d, t) in define_map.into_iter() { match t { @@ -51,7 +52,7 @@ pub fn parse_file(path: &str) -> Result> { }, LineType::IncDir(incdirs) => { for dir in incdirs { - filelist.incdirs.push(dir.to_string()); + filelist.incdirs.push(PathBuf::from(dir)); } } LineType::Comment => filelist.comments_present = true, diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 6e95fcd..63bb7f2 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1,5 +1,6 @@ use sv_filelist_parser; use std::collections::HashMap; +use std::path::PathBuf; #[test] fn simple_test() { @@ -12,11 +13,13 @@ fn simple_test() { defines.insert("RTL".to_string(), None); let filelist_exp = sv_filelist_parser::Filelist { - files : vec!["testcase/file1.sv".to_string(), - "testcase/file2.sv".to_string(), - "testcase/file3.sv".to_string(), - "testcase/file4.sv".to_string(),], - incdirs : vec!["testcase/".to_string()], + files : vec![ + PathBuf::from("testcase/file1.sv"), + PathBuf::from("testcase/file2.sv"), + PathBuf::from("testcase/file3.sv"), + PathBuf::from("testcase/file4.sv"), + ], + incdirs : vec![PathBuf::from("testcase/")], defines : defines, comments_present : true };