summaryrefslogtreecommitdiffstats
path: root/src/hostfile.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-03-19 21:40:05 -0500
committerToby Vincent <tobyv13@gmail.com>2023-03-19 21:40:05 -0500
commit6b0ca0d87fa180262ff651d287a3d09e92480178 (patch)
tree791cade20a81bf25d3ed4dbf0f63dcdb6d5a049a /src/hostfile.rs
parent82598a3adc9d950c34346ccd0128d6ef78bbb437 (diff)
feat: impl SessionSource for /etc/hosts
Diffstat (limited to 'src/hostfile.rs')
-rw-r--r--src/hostfile.rs19
1 files changed, 19 insertions, 0 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)
+ }
+}