-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error handling when the path passed to include directive could no…
- Loading branch information
Showing
3 changed files
with
14 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
use std::{fs::File, io::Read, path::PathBuf}; | ||
use anyhow::{anyhow, Result}; | ||
|
||
pub fn path_to_content(path: PathBuf) -> String { | ||
let mut content = String::new(); | ||
use std::{fs::read_to_string, path::PathBuf}; | ||
|
||
// Not handle cases where files are not found because make command cannot be | ||
// executed in the first place if Makefile or included files are not found. | ||
let mut f = File::open(path).unwrap(); | ||
f.read_to_string(&mut content).unwrap(); | ||
|
||
content | ||
pub fn path_to_content(path: PathBuf) -> Result<String> { | ||
read_to_string(path.as_path()).map_err(|e| anyhow!(e)) | ||
} |