Skip to content

Commit

Permalink
Bump dep, fix hanging re serde json
Browse files Browse the repository at this point in the history
  • Loading branch information
kimono-koans committed Dec 22, 2023
1 parent 735a12f commit fad5172
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 39 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ proc-mounts = { version = "0.3.0", default-features = false }
once_cell = { version = "1.18.0", default-features = false }
hashbrown = { version = "0.14.2", default-features = false, features = ["rayon", "ahash", "inline-more"] }
nix = { version = "0.27.1", default-features = false, features = ["fs", "user", "zerocopy"] }
serde = { version = "1.0.192", default-features = false }
serde_json = { version = "1.0.108", default-features = false, features = ["preserve_order"] }
serde = { version = "1.0.193" }
serde_json = { version = "1.0.108", features = ["preserve_order", "std"] }
filetime = { version = "0.2.22", default-features = false }
realpath-ext = { version = "0.1.3", default-features = false, features = ["std"] }
# these are strictly not required to build, only included for attribution sake (to be picked up by cargo_about)
Expand Down
35 changes: 7 additions & 28 deletions src/display_map/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
// For the full copyright and license information, please view the LICENSE file
// that was distributed with this source code.

use crate::config::generate::{ExecMode, MountDisplay, PrintMode};
use crate::config::generate::{MountDisplay, PrintMode};
use crate::data::paths::ZfsSnapPathGuard;
use crate::display_versions::format::{NOT_SO_PRETTY_FIXED_WIDTH_PADDING, QUOTATION_MARKS_LEN};
use crate::library::utility::delimiter;
use crate::{MountsForFiles, SnapNameMap, VersionsMap, GLOBAL_CONFIG};
use serde::ser::SerializeStruct;
use serde::ser::SerializeMap;
use serde::{Serialize, Serializer};
use std::borrow::Cow;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -50,9 +50,10 @@ impl Serialize for PrintAsMap {
where
S: Serializer,
{
let mut state = serializer.serialize_struct("PrintAsMap", 1)?;

state.serialize_field("inner", &self)?;
let mut state = serializer.serialize_map(Some(self.inner.len()))?;
self.inner
.iter()
.try_for_each(|(k, v)| state.serialize_entry(k, v))?;
state.end()
}
}
Expand Down Expand Up @@ -139,29 +140,7 @@ impl From<&SnapNameMap> for PrintAsMap {
impl std::string::ToString for PrintAsMap {
fn to_string(&self) -> String {
if GLOBAL_CONFIG.opt_json {
let json_string = self.to_json();

let res = match &GLOBAL_CONFIG.exec_mode {
ExecMode::BasicDisplay | ExecMode::Interactive(_) => {
json_string.replace("\"inner\": ", "\"versions\": ")
}
ExecMode::MountsForFiles(_) => json_string.replace("\"inner\": ", "\"mounts\": "),
ExecMode::SnapsForFiles(_) => {
json_string.replace("\"inner\": ", "\"snapshot_names\": ")
}
ExecMode::NonInteractiveRecursive(_)
| ExecMode::RollForward(_)
| ExecMode::NumVersions(_)
| ExecMode::Prune(_)
| ExecMode::SnapFileMount(_) => {
unreachable!(
"JSON print should not be available in the selected {:?} execution mode.",
&GLOBAL_CONFIG.exec_mode
);
}
};

return res;
return self.to_json();
}

let delimiter = delimiter();
Expand Down
10 changes: 5 additions & 5 deletions src/display_versions/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::data::paths::PathData;
use crate::display_map::format::PrintAsMap;
use crate::library::utility::delimiter;
use crate::lookup::versions::VersionsMap;
use serde::ser::SerializeStruct;
use serde::ser::SerializeMap;
use serde::{Serialize, Serializer};
use std::collections::BTreeMap;
use std::ops::Deref;
Expand Down Expand Up @@ -91,9 +91,6 @@ impl<'a> Serialize for VersionsDisplayWrapper<'a> {
where
S: Serializer,
{
// 3 is the number of fields in the struct.
let mut state = serializer.serialize_struct("VersionMap", 1)?;

// add live file key to values if needed before serializing
let new_map: BTreeMap<String, Vec<PathData>> = self
.deref()
Expand All @@ -110,7 +107,10 @@ impl<'a> Serialize for VersionsDisplayWrapper<'a> {
})
.collect();

state.serialize_field("versions", &new_map)?;
let mut state = serializer.serialize_map(Some(new_map.len()))?;
new_map
.iter()
.try_for_each(|(k, v)| state.serialize_entry(k, v))?;
state.end()
}
}

0 comments on commit fad5172

Please sign in to comment.