~garritfra/taurus

Simplify Config::load v1 APPLIED

Josh Leeb-du Toit: 1
 Simplify Config::load

 1 files changed, 4 insertions(+), 9 deletions(-)
Applied. Thanks!
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~garritfra/taurus/patches/16044/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Simplify Config::load Export this patch

Simplify Config::load by using the fs::read_to_string function provided
in std. Additionally, we update the type of the config_path argument to
be generic over AsRef<Path> which is generally preferred over &str for
file path arguments.
---
 src/config.rs | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/src/config.rs b/src/config.rs
index ced5c37..3b42d30 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,6 +1,5 @@
use serde::Deserialize;
use std::fs;
use std::io::prelude::*;
use std::{fs, path::Path};

#[derive(Deserialize)]
pub struct Config {
@@ -13,12 +12,8 @@ pub struct Config {
}

impl Config {
    pub fn load(config_path: &str) -> anyhow::Result<Self> {
        let mut file = fs::File::open(config_path)?;
        let mut contents = String::new();

        file.read_to_string(&mut contents)?;

        Ok(toml::from_str(&contents)?)
    pub fn load<P: AsRef<Path>>(config_path: P) -> anyhow::Result<Self> {
        let buf = fs::read_to_string(config_path)?;
        toml::from_str(&buf).map_err(|e| e.into())
    }
}
-- 
2.29.2
Looks good