Skip to content

Commit

Permalink
to collections return reference instead of move data out of Edn.
Browse files Browse the repository at this point in the history
  • Loading branch information
Grinkers committed May 1, 2024
1 parent d3022d4 commit c60d05b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/edn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ impl Vector {
}

#[must_use]
pub fn to_vec(self) -> Vec<Edn> {
self.0
pub const fn to_vec(&self) -> &Vec<Edn> {
&self.0
}
}

Expand All @@ -122,8 +122,8 @@ impl List {
}

#[must_use]
pub fn to_vec(self) -> Vec<Edn> {
self.0
pub const fn to_vec(&self) -> &Vec<Edn> {
&self.0
}
}

Expand All @@ -144,8 +144,8 @@ impl Set {
}

#[must_use]
pub fn to_set(self) -> BTreeSet<Edn> {
self.0
pub const fn to_set(&self) -> &BTreeSet<Edn> {
&self.0
}
}

Expand All @@ -164,8 +164,8 @@ impl Map {
}

#[must_use]
pub fn to_map(self) -> BTreeMap<String, Edn> {
self.0
pub const fn to_map(&self) -> &BTreeMap<String, Edn> {
&self.0
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
Expand Down

0 comments on commit c60d05b

Please sign in to comment.