From 090120a834dae463a3f9edb9c1f0d8453fd8ef8c Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Sun, 9 May 2021 18:34:15 +0100 Subject: 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 --- atuin-client/src/import/mod.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'atuin-client/src/import/mod.rs') 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) -> Result { +fn count_lines(buf: &mut BufReader) -> Result { let lines = buf.lines().count(); buf.seek(SeekFrom::Start(0))?; Ok(lines) } + +pub trait Importer: IntoIterator> + Sized { + const NAME: &'static str; + fn histpath() -> Result; + fn parse(path: impl AsRef) -> Result; +} -- cgit v1.3.1