diff --git a/libconfig/src/lib.rs b/libconfig/src/lib.rs index f1bf1b1..af654d0 100644 --- a/libconfig/src/lib.rs +++ b/libconfig/src/lib.rs @@ -11,17 +11,17 @@ pub mod net_settings; pub mod bootgen; #[derive(Debug)] -pub enum Error<'a> { +pub enum Error { SdError(sdio::sd_card::CardInitializationError), IoError(io::Error), Utf8Error(FromUtf8Error), - KeyNotFoundError(&'a str), + KeyNotFoundError(String), NoConfig, } -pub type Result<'a, T> = core::result::Result>; +pub type Result = core::result::Result; -impl<'a> fmt::Display for Error<'a> { +impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::SdError(error) => write!(f, "SD error: {}", error), @@ -33,29 +33,29 @@ impl<'a> fmt::Display for Error<'a> { } } -impl<'a> From for Error<'a> { +impl From for Error { fn from(error: sdio::sd_card::CardInitializationError) -> Self { Error::SdError(error) } } -impl<'a> From for Error<'a> { +impl From for Error { fn from(error: io::Error) -> Self { Error::IoError(error) } } -impl<'a> From for Error<'a> { +impl From for Error { fn from(error: FromUtf8Error) -> Self { Error::Utf8Error(error) } } -fn parse_config<'a>( - key: &'a str, +fn parse_config( + key: &str, buffer: &mut Vec, file: fatfs::File, -) -> Result<'a, ()> { +) -> Result<()> { let prefix = [key, "="].concat().to_ascii_lowercase(); for line in BufReader::new(file).lines() { let line = line?.to_ascii_lowercase(); @@ -64,7 +64,7 @@ fn parse_config<'a>( return Ok(()); } } - Err(Error::KeyNotFoundError(key)) + Err(Error::KeyNotFoundError(key.into())) } pub struct Config { @@ -74,7 +74,7 @@ pub struct Config { const NEWLINE: &[u8] = b"\n"; impl Config { - pub fn new() -> Result<'static, Self> { + pub fn new() -> Result { let sdio = sdio::Sdio::sdio0(true); if !sdio.is_card_inserted() { Err(sdio::sd_card::CardInitializationError::NoCardInserted)?; @@ -94,7 +94,7 @@ impl Config { Config { fs: None } } - pub fn read<'b>(&self, key: &'b str) -> Result<'b, Vec> { + pub fn read(&self, key: &str) -> Result> { if let Some(fs) = &self.fs { let root_dir = fs.root_dir(); let mut buffer: Vec = Vec::new(); @@ -102,7 +102,7 @@ impl Config { Ok(mut f) => f.read_to_end(&mut buffer).map(|_| ())?, Err(_) => match root_dir.open_file("/CONFIG.TXT") { Ok(f) => parse_config(key, &mut buffer, f)?, - Err(_) => return Err(Error::KeyNotFoundError(key)), + Err(_) => return Err(Error::KeyNotFoundError(key.into())), }, }; Ok(buffer) @@ -111,11 +111,11 @@ impl Config { } } - pub fn read_str<'b>(&self, key: &'b str) -> Result<'b, String> { + pub fn read_str(&self, key: &str) -> Result { Ok(String::from_utf8(self.read(key)?)?) } - pub fn remove<'b>(&self, key: &'b str) -> Result<'b, ()> { + pub fn remove(&self, key: &str) -> Result<()> { if let Some(fs) = &self.fs { let root_dir = fs.root_dir(); match root_dir.remove(&["/CONFIG/", key, ".BIN"].concat()) { @@ -136,7 +136,7 @@ impl Config { } Ok(()) }, - Err(_) => Err(Error::KeyNotFoundError(key)) + Err(_) => Err(Error::KeyNotFoundError(key.into())) } } } @@ -145,7 +145,7 @@ impl Config { } } - pub fn write<'b>(&self, key: &'b str, value: Vec) -> Result<'b, ()> { + pub fn write(&self, key: &str, value: Vec) -> Result<()> { if self.fs.is_none() { return Err(Error::NoConfig); }