nostrdb-rs

nostrdb in rust!
git clone git://jb55.com/nostrdb-rs
Log | Files | Refs | Submodules | README | LICENSE

commit 4c89dcbca13168758eb41752225b4e486dbc9d20
parent 385a1af481ff8c08949a885248544483a52acbeb
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 21 Aug 2024 06:58:26 +0300

since/limit mut methods

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/filter.rs | 36+++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/filter.rs b/src/filter.rs @@ -188,7 +188,7 @@ impl Filter { unsafe { &*(self.as_ptr()) }.num_elements } - pub fn limit(self, limit: u64) -> Self { + pub fn limit_mut(self, limit: u64) -> Self { for field in self.mut_iter() { if let MutFilterField::Limit(val) = field { *val = limit; @@ -199,7 +199,7 @@ impl Filter { Filter::copy_from(&self).limit(limit).build() } - pub fn until(self, until: u64) -> Self { + pub fn until_mut(self, until: u64) -> Self { for field in self.mut_iter() { if let MutFilterField::Until(val) = field { *val = until; @@ -210,7 +210,37 @@ impl Filter { Filter::copy_from(&self).until(until).build() } - pub fn since(self, since: u64) -> Self { + pub fn since(&self) -> Option<u64> { + for field in self { + if let FilterField::Since(since) = field { + return Some(since); + } + } + + None + } + + pub fn limit(&self) -> Option<u64> { + for field in self { + if let FilterField::Limit(limit) = field { + return Some(limit); + } + } + + None + } + + pub fn until(&self) -> Option<u64> { + for field in self { + if let FilterField::Until(until) = field { + return Some(until); + } + } + + None + } + + pub fn since_mut(self, since: u64) -> Self { for field in self.mut_iter() { if let MutFilterField::Since(val) = field { *val = since;