diff options
author | Toby Vincent <tobyv13@gmail.com> | 2023-03-19 21:40:05 -0500 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2023-03-19 21:40:05 -0500 |
commit | 6b0ca0d87fa180262ff651d287a3d09e92480178 (patch) | |
tree | 791cade20a81bf25d3ed4dbf0f63dcdb6d5a049a /src | |
parent | 82598a3adc9d950c34346ccd0128d6ef78bbb437 (diff) |
feat: impl SessionSource for /etc/hosts
Diffstat (limited to 'src')
-rw-r--r-- | src/hostfile.rs | 19 | ||||
-rw-r--r-- | src/lib.rs | 3 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/hostfile.rs b/src/hostfile.rs new file mode 100644 index 0000000..5414125 --- /dev/null +++ b/src/hostfile.rs @@ -0,0 +1,19 @@ +use crate::{Session, SessionSource}; + +pub struct HostFile; + +impl SessionSource for HostFile { + type Error = &'static str; + + type Iter = Vec<Session>; + + fn sessions(&self) -> Result<Self::Iter, Self::Error> { + let sessions = hostfile::parse_hostfile()? + .into_iter() + .flat_map(|h| h.names.into_iter()) + .map(Into::into) + .collect(); + + Ok(sessions) + } +} @@ -13,11 +13,12 @@ pub use tmux::Tmux; mod config; mod history; +mod hostfile; mod ssh; mod tmux; pub trait SessionSource { - type Error: std::error::Error; + type Error; type Iter: IntoIterator<Item = Session>; |