From dd590a9dfb8d217d1aa24f7137ce0175102f63b4 Mon Sep 17 00:00:00 2001 From: Gerrit Viljoen Date: Sun, 17 May 2020 11:28:14 +0200 Subject: [PATCH] save game --- src/lib.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f99e911..79ae374 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -362,20 +362,26 @@ struct SmartString { impl SmartString { fn new() -> Self { - todo!() + Self { fragments: Vec::new() } } fn from(string: T) -> Self where T: Display { - todo!() + // TODO: + Self { fragments: vec![(true, string.to_string())] } } fn char_len(&self) -> usize { - todo!() + self.fragments.iter() + .filter(|(visible, _)| *visible) + .map(|(_, string)| string.chars().count()) + .sum() } fn is_empty(&self) -> bool { - todo!() + self.fragments.iter() + .filter(|(visible, _)| *visible) + .all(|(_, string)| string.is_empty()) } fn pop(&mut self) -> Option {