From a01fcbee68827ac517f72af017680ae3be48c2ba Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Sat, 26 Nov 2022 17:59:57 -0800 Subject: [PATCH] Still not working. --- crates/squozen/src/squozen.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/squozen/src/squozen.rs b/crates/squozen/src/squozen.rs index 524020e..a8d2f34 100644 --- a/crates/squozen/src/squozen.rs +++ b/crates/squozen/src/squozen.rs @@ -31,14 +31,14 @@ pub impl Squozen { } /* - pub fn iter(&mut self) -> StoredPath { - FoundPath::new(&self); + pub fn matches(&mut self, pattern: &[u8]) -> StoredPath { + FoundPath::new(&self, pattern); } */ } pub struct StoredPath<'a> { - source: Squozen, + source: &'a Squozen, path: [char; libc::PATH_MAX], db: Bytes, ch: u8, @@ -47,7 +47,7 @@ pub struct StoredPath<'a> { } pub impl<'a> StoredPath { - pub fn new(squozen: Squozen) -> StoredPath { + pub fn new(squozen: &'a mut Squozen) -> StoredPath { let mut dbfile = File::open(&squozen.path)?; let mut dbbuffer = Bufreader::new(dbfile); dbbuffer.seek(BIGRAMS); @@ -104,3 +104,17 @@ pub impl<'a> Iterator for StoredPath { Some(&self.path) } } + +pub struct FoundPath { + stored: StoredPath, + pattern: Vec, +} + +pub impl<'a> FoundPath { + pub fn new(squozen: &'a Squozen, path: &[u8]) -> Result { + Ok(FoundPath { + stored: StoredPath::new(squozen), + pattern: prepare_pattern(path)?, + }) + } +}