summaryrefslogtreecommitdiff
path: root/src/info_file.rs
diff options
context:
space:
mode:
authorMo <76752051+mo8it@users.noreply.github.com>2024-04-24 02:56:20 +0200
committerGitHub <noreply@github.com>2024-04-24 02:56:20 +0200
commit53fdb9044d54dbdf5f0aa6c309cd285829a04b3a (patch)
treeb45b6f11597130690232b2eaa9621f25ecf98200 /src/info_file.rs
parent86684b7fc9dd5e8bedad6056565645d1d980925c (diff)
parent8a085a0a85c759029cd57c28364867bde817e738 (diff)
Merge pull request #1955 from rust-lang/solutions
Solutions
Diffstat (limited to 'src/info_file.rs')
-rw-r--r--src/info_file.rs29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/info_file.rs b/src/info_file.rs
index 879609e..f344464 100644
--- a/src/info_file.rs
+++ b/src/info_file.rs
@@ -1,6 +1,8 @@
use anyhow::{bail, Context, Error, Result};
use serde::Deserialize;
-use std::fs;
+use std::{fs, io::ErrorKind};
+
+use crate::DEBUG_PROFILE;
// The mode of the exercise.
#[derive(Deserialize, Copy, Clone)]
@@ -46,18 +48,27 @@ pub struct InfoFile {
}
impl InfoFile {
+ fn from_embedded() -> Result<Self> {
+ toml_edit::de::from_str(include_str!("../info.toml"))
+ .context("Failed to parse the embedded `info.toml` file")
+ }
+
pub fn parse() -> Result<Self> {
+ if DEBUG_PROFILE {
+ return Self::from_embedded();
+ }
+
// Read a local `info.toml` if it exists.
- let slf: Self = match fs::read_to_string("info.toml") {
- Ok(file_content) => toml_edit::de::from_str(&file_content)
+ let slf = match fs::read_to_string("info.toml") {
+ Ok(file_content) => toml_edit::de::from_str::<Self>(&file_content)
.context("Failed to parse the `info.toml` file")?,
- Err(e) => match e.kind() {
- std::io::ErrorKind::NotFound => {
- toml_edit::de::from_str(include_str!("../info.toml"))
- .context("Failed to parse the embedded `info.toml` file")?
+ Err(e) => {
+ if e.kind() == ErrorKind::NotFound {
+ return Self::from_embedded();
}
- _ => return Err(Error::from(e).context("Failed to read the `info.toml` file")),
- },
+
+ return Err(Error::from(e).context("Failed to read the `info.toml` file"));
+ }
};
if slf.exercises.is_empty() {