diff --git a/Cargo.lock b/Cargo.lock index f318965a..5acc8438 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,6 +97,7 @@ dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", + "serde", "winapi", ] diff --git a/Cargo.toml b/Cargo.toml index 07a9dfb5..ca1bc5ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,10 @@ version = "0.26.0" doctest = true [dependencies] -chrono = { version = "0.4.19", default-features = false, features = ["clock"] } +chrono = { version = "0.4.19", default-features = false, features = [ + "clock", + "serde", +] } clipboard = { version = "0.5.0", optional = true } crossbeam = { version = "0.8.2", optional = true } crossterm = { version = "0.27.0", features = ["serde"] } diff --git a/src/history/item.rs b/src/history/item.rs index 3696f3c7..0c36fba3 100644 --- a/src/history/item.rs +++ b/src/history/item.rs @@ -5,9 +5,8 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::{fmt::Display, time::Duration}; /// Unique ID for the [`HistoryItem`]. More recent items have higher ids than older ones. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] pub struct HistoryItemId(pub i64); - impl HistoryItemId { /// Create a new `HistoryItemId` value pub const fn new(i: i64) -> HistoryItemId { @@ -22,7 +21,7 @@ impl Display for HistoryItemId { } /// Unique ID for the session in which reedline was run to disambiguate different sessions -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct HistorySessionId(pub(crate) i64); impl HistorySessionId { pub(crate) const fn new(i: i64) -> HistorySessionId { @@ -79,7 +78,7 @@ impl<'de> Deserialize<'de> for IgnoreAllExtraInfo { impl HistoryItemExtraInfo for IgnoreAllExtraInfo {} /// Represents one run command with some optional additional context -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct HistoryItem { /// primary key, unique across one history pub id: Option, @@ -99,6 +98,9 @@ pub struct HistoryItem { /// the exit status of the command pub exit_status: Option, /// arbitrary additional information that might be interesting + /// NOTE: this attribute is required because of https://github.com/rust-lang/rust/issues/41617 + /// (see https://github.com/serde-rs/serde/issues/1296#issuecomment-394056188 for the fix) + #[serde(deserialize_with = "Option::::deserialize")] pub more_info: Option, }