From 0722a6fc3b66525f275a73d7d29f781683ff714c Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 26 Nov 2023 23:32:52 -0700 Subject: [PATCH] marginal progression woooo --- src/main.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 81c42ec..93a3765 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,18 +84,14 @@ impl Storage { fn from(&self, t: SystemTime) -> Storage { let mut result = Storage{xs: vec![]}; self.xs.iter() - .filter(|x| !x.clone().clone().before(t)) + .filter(|x| x.ts() >= t) .for_each(|x| result.xs.push(x.clone())); result } } impl X { - fn before(self, t: SystemTime) -> bool { - self.ts() < t - } - - fn ts(self) -> SystemTime { + fn ts(&self) -> SystemTime { UNIX_EPOCH.add(Duration::from_secs(self.t.try_into().unwrap())) } } @@ -109,11 +105,13 @@ mod test_storage { let given = Storage{xs: vec![ X{t: 1, x: "def".to_string(), tag: "abc".to_string()}, X{t: 2, x: "ghi".to_string(), tag: "".to_string()}, + X{t: 3, x: "jkl".to_string(), tag: "".to_string()}, ]}; let want = Storage{xs: vec![ X{t: 2, x: "ghi".to_string(), tag: "".to_string()}, + X{t: 3, x: "jkl".to_string(), tag: "".to_string()}, ]}; - let got = given.from(UNIX_EPOCH.add(Duration::from_secs(1))); + let got = given.from(UNIX_EPOCH.add(Duration::from_secs(2))); assert_eq!(got, want); } }