Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to collections return reference instead of move data out of Edn. #153

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading