forked from esrlabs/chipmunk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[esrlabs#1966] Add the BuildConfiguration struct
The BuildConfiguration struct will hold the build configuration loaded from the configuration file. For the moment it just loads the file contents into a string and handles failures.
- Loading branch information
1 parent
d59df6f
commit caffa9c
Showing
3 changed files
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/* |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use core::fmt; | ||
use std::fs; | ||
|
||
const DEFAULT_BUILD_CONFIG_FILE:&str = "build.toml"; | ||
|
||
pub struct ReadError { | ||
pub file_name: String, | ||
pub message: String | ||
} | ||
|
||
impl fmt::Display for ReadError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{}: {}", self.file_name, self.message) | ||
} | ||
} | ||
|
||
pub struct BuildConfiguration { | ||
pub source_file: String, | ||
text: String | ||
} | ||
|
||
impl BuildConfiguration { | ||
pub fn from_file(file_name: Option<String>) -> Result<Self, ReadError> { | ||
let actual_file_name = file_name.unwrap_or(DEFAULT_BUILD_CONFIG_FILE.to_string()); | ||
let result = fs::read_to_string(&actual_file_name); | ||
|
||
match result { | ||
Err(error) => { | ||
Err(ReadError { | ||
file_name: actual_file_name, | ||
message: format!("Unable to read file: {}", error) | ||
}) | ||
}, | ||
Ok(text) => { | ||
Ok(Self { source_file: actual_file_name, text }) | ||
} | ||
} | ||
} | ||
} |
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,3 +1,5 @@ | ||
mod build_configuration; | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
} |