diff options
author | Conrad Ludgate <conradludgate@gmail.com> | 2021-05-09 18:34:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-09 18:34:15 +0100 |
commit | 090120a834dae463a3f9edb9c1f0d8453fd8ef8c (patch) | |
tree | 6f78aca3872d546df28d7af5401088845335c9d1 /atuin-client/src/import/mod.rs | |
parent | 725ea9b16b1e3596b394fa7e47e02a9331de10cf (diff) |
Generic Importer Trait (#71)
* initial importer trait
* appease linters
* improve file handling. fixes #66
* use size hint
* format + comment
* update serde rename mess
* tested :sunglasses: :rocket:
* small formatting
Diffstat (limited to 'atuin-client/src/import/mod.rs')
-rw-r--r-- | atuin-client/src/import/mod.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/atuin-client/src/import/mod.rs b/atuin-client/src/import/mod.rs index 0b21d605..d73d3857 100644 --- a/atuin-client/src/import/mod.rs +++ b/atuin-client/src/import/mod.rs @@ -1,16 +1,24 @@ -use std::fs::File; -use std::io::{BufRead, BufReader, Seek, SeekFrom}; +use std::io::{BufRead, BufReader, Read, Seek, SeekFrom}; +use std::path::{Path, PathBuf}; use eyre::Result; +use crate::history::History; + pub mod bash; pub mod resh; pub mod zsh; // this could probably be sped up -fn count_lines(buf: &mut BufReader<File>) -> Result<usize> { +fn count_lines(buf: &mut BufReader<impl Read + Seek>) -> Result<usize> { let lines = buf.lines().count(); buf.seek(SeekFrom::Start(0))?; Ok(lines) } + +pub trait Importer: IntoIterator<Item = Result<History>> + Sized { + const NAME: &'static str; + fn histpath() -> Result<PathBuf>; + fn parse(path: impl AsRef<Path>) -> Result<Self>; +} |