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

Make history-related items (de-)serializable #678

Merged
merged 5 commits into from
Dec 6, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
10 changes: 6 additions & 4 deletions src/history/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
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 {
Expand All @@ -22,7 +21,7 @@
}

/// 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)]

Check warning on line 24 in src/history/item.rs

View check run for this annotation

Codecov / codecov/patch

src/history/item.rs#L24

Added line #L24 was not covered by tests
pub struct HistorySessionId(pub(crate) i64);
impl HistorySessionId {
pub(crate) const fn new(i: i64) -> HistorySessionId {
Expand Down Expand Up @@ -79,7 +78,7 @@
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<ExtraInfo: HistoryItemExtraInfo = IgnoreAllExtraInfo> {
/// primary key, unique across one history
pub id: Option<HistoryItemId>,
Expand All @@ -99,6 +98,9 @@
/// the exit status of the command
pub exit_status: Option<i64>,
/// 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::<ExtraInfo>::deserialize")]
pub more_info: Option<ExtraInfo>,
}

Expand Down