From c60d05b6e7e29394dff8f72b15a8e7a78f43a017 Mon Sep 17 00:00:00 2001 From: Kevin Nakamura Date: Thu, 2 May 2024 03:08:26 +0900 Subject: [PATCH] `to` collections return reference instead of move data out of `Edn`. --- src/edn/mod.rs | 16 ++++++++-------- src/json/mod.rs | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/edn/mod.rs b/src/edn/mod.rs index 2fa6be6..62cd6de 100644 --- a/src/edn/mod.rs +++ b/src/edn/mod.rs @@ -102,8 +102,8 @@ impl Vector { } #[must_use] - pub fn to_vec(self) -> Vec { - self.0 + pub const fn to_vec(&self) -> &Vec { + &self.0 } } @@ -122,8 +122,8 @@ impl List { } #[must_use] - pub fn to_vec(self) -> Vec { - self.0 + pub const fn to_vec(&self) -> &Vec { + &self.0 } } @@ -144,8 +144,8 @@ impl Set { } #[must_use] - pub fn to_set(self) -> BTreeSet { - self.0 + pub const fn to_set(&self) -> &BTreeSet { + &self.0 } } @@ -164,8 +164,8 @@ impl Map { } #[must_use] - pub fn to_map(self) -> BTreeMap { - self.0 + pub const fn to_map(&self) -> &BTreeMap { + &self.0 } } diff --git a/src/json/mod.rs b/src/json/mod.rs index 288984b..8c7ce33 100644 --- a/src/json/mod.rs +++ b/src/json/mod.rs @@ -10,11 +10,11 @@ use crate::edn::{rational_to_double, Edn}; #[allow(clippy::module_name_repetitions)] pub fn display_as_json(edn: &Edn) -> String { match edn { - Edn::Vector(v) => vec_to_json(&v.clone().to_vec()), + Edn::Vector(v) => vec_to_json(v.to_vec()), #[cfg(feature = "sets")] - Edn::Set(s) => set_to_json_vec(&s.clone().to_set()), - Edn::Map(map) => map_to_json(&map.clone().to_map()), - Edn::List(l) => vec_to_json(&l.clone().to_vec()), + Edn::Set(s) => set_to_json_vec(s.to_set()), + Edn::Map(map) => map_to_json(map.to_map()), + Edn::List(l) => vec_to_json(l.to_vec()), Edn::Key(key) => format!("{:?}", kebab_to_camel(key)), Edn::Symbol(s) | Edn::Str(s) => format!("{s:?}"), Edn::Int(n) => format!("{n}"),