From 74f91a620177f8f02be22c652ae09d04433665b8 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 5 May 2024 22:37:19 +0200 Subject: [PATCH] chore: refactor Signed-off-by: kjuulh --- crates/hyperlog-core/src/log.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/crates/hyperlog-core/src/log.rs b/crates/hyperlog-core/src/log.rs index fadbbcb..9bfa142 100644 --- a/crates/hyperlog-core/src/log.rs +++ b/crates/hyperlog-core/src/log.rs @@ -32,8 +32,9 @@ impl GraphItem { pub fn get(&self, path: &[&str]) -> Option<&GraphItem> { match path.split_first() { Some((first, rest)) => match self { - GraphItem::User(u) => u.get(*first)?.get(rest), - GraphItem::Section(s) => s.get(*first)?.get(rest), + GraphItem::User(section) | GraphItem::Section(section) => { + section.get(*first)?.get(rest) + } GraphItem::Item { .. } => None, }, None => Some(self), @@ -43,8 +44,9 @@ impl GraphItem { pub fn get_mut(&mut self, path: &[&str]) -> Option<&mut GraphItem> { match path.split_first() { Some((first, rest)) => match self { - GraphItem::User(u) => u.get_mut(*first)?.get_mut(rest), - GraphItem::Section(s) => s.get_mut(*first)?.get_mut(rest), + GraphItem::User(section) | GraphItem::Section(section) => { + section.get_mut(*first)?.get_mut(rest) + } GraphItem::Item { .. } => None, }, None => Some(self), @@ -54,20 +56,12 @@ impl GraphItem { pub fn take(&mut self, path: &[&str]) -> Option { match path.split_first() { Some((first, rest)) => match self { - GraphItem::User(u) => { + GraphItem::User(section) | GraphItem::Section(section) => { if rest.is_empty() { - let val = u.remove(*first); + let val = section.remove(*first); val.map(|v| *v) } else { - u.get_mut(*first)?.take(rest) - } - } - GraphItem::Section(s) => { - if rest.is_empty() { - let val = s.remove(*first); - val.map(|v| *v) - } else { - s.get_mut(*first)?.take(rest) + section.get_mut(*first)?.take(rest) } } GraphItem::Item { .. } => None,