improved power handling

This commit is contained in:
Robin Appelman 2023-07-17 21:01:12 +02:00
commit 224bf80588
6 changed files with 79 additions and 54 deletions

View file

@ -3,6 +3,7 @@ use std::io;
use std::io::{ErrorKind, Read, Seek};
use std::path::{Path, PathBuf};
use std::str::FromStr;
use tracing::{debug, instrument, warn};
fn read_to_string_trimmed(path: &Path) -> io::Result<String> {
let mut s = read_to_string(path)?;
@ -17,10 +18,15 @@ pub struct FileSource {
}
impl FileSource {
#[instrument(skip_all, fields(path = ?path.as_ref()))]
pub fn open<P: AsRef<Path>>(path: P) -> io::Result<FileSource> {
debug!("opening sensor");
Ok(FileSource {
buff: String::with_capacity(32),
file: File::open(path)?,
file: File::open(path).map_err(|e| {
warn!("failed to open sensor");
e
})?,
})
}