From 62a53f9718b36697d91b1328817893b9aa40683a Mon Sep 17 00:00:00 2001 From: Andre Popovitch Date: Wed, 27 Apr 2022 16:12:19 -0500 Subject: [PATCH] Add serde --- Cargo.lock | 21 +++++++++++++++++++++ Cargo.toml | 1 + src/lines.rs | 3 ++- src/positions.rs | 3 ++- src/summary.rs | 5 +++-- src/syntax.rs | 9 +++++---- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d709b97477..e66e9e6bcc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -181,6 +181,7 @@ dependencies = [ "regex", "rpds", "rustc-hash", + "serde", "strsim", "term_size", "tree-sitter", @@ -463,6 +464,26 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "serde" +version = "1.0.136" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.136" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "static_assertions" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index b9692b50cf..a49e02409a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ const_format = "0.2.22" owo-colors = "3.2.0" rpds = "0.10.0" wu-diff = "0.1.2" +serde = { version = "1.0", features = ["derive"] } [dev-dependencies] pretty_assertions = "1.0.0" diff --git a/src/lines.rs b/src/lines.rs index 6090cdf664..6cb664cb4d 100644 --- a/src/lines.rs +++ b/src/lines.rs @@ -1,6 +1,7 @@ //! Manipulate lines of text and groups of lines. use crate::positions::SingleLineSpan; +use serde::{Deserialize, Serialize}; use std::{ cmp::{max, Ordering}, fmt, @@ -10,7 +11,7 @@ use std::{ /// other numerical data. /// /// Zero-indexed internally. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct LineNumber(pub usize); impl LineNumber { diff --git a/src/positions.rs b/src/positions.rs index 3506b2fb74..daaa2ad02d 100644 --- a/src/positions.rs +++ b/src/positions.rs @@ -1,9 +1,10 @@ //! Represents positions within a string. use crate::lines::LineNumber; +use serde::{Deserialize, Serialize}; /// A range within a single line of a string. -#[derive(Debug, PartialEq, Clone, Copy, Eq, PartialOrd, Ord, Hash)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy, Eq, PartialOrd, Ord, Hash)] pub struct SingleLineSpan { /// All zero-indexed. pub line: LineNumber, diff --git a/src/summary.rs b/src/summary.rs index e7e7273cd2..bb86dda8fb 100644 --- a/src/summary.rs +++ b/src/summary.rs @@ -1,12 +1,13 @@ use crate::syntax::MatchedPos; +use serde::{Deserialize, Serialize}; -#[derive(Debug, PartialEq, Eq)] +#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)] pub enum FileContent { Text(String), Binary(Vec), } -#[derive(Debug)] +#[derive(Serialize, Deserialize, Debug)] pub struct DiffResult { pub path: String, pub language: Option, diff --git a/src/syntax.rs b/src/syntax.rs index 84eae013fe..8370561ad9 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -2,6 +2,7 @@ #![allow(clippy::mutable_key_type)] // Hash for Syntax doesn't use mutable fields. +use serde::{Deserialize, Serialize}; use std::{ cell::Cell, collections::HashMap, @@ -552,7 +553,7 @@ impl<'a> Hash for Syntax<'a> { } } -#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash)] +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Copy, Hash)] pub enum AtomKind { Normal, String, @@ -562,14 +563,14 @@ pub enum AtomKind { } /// Unlike atoms, tokens can be delimiters like `{`. -#[derive(PartialEq, Eq, Debug, Clone, Copy)] +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Copy)] pub enum TokenKind { Delimiter, Atom(AtomKind), } /// A matched token (an atom, a delimiter, or a comment word). -#[derive(PartialEq, Eq, Debug, Clone)] +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)] pub enum MatchKind { UnchangedToken { highlight: TokenKind, @@ -598,7 +599,7 @@ impl MatchKind { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] pub struct MatchedPos { pub kind: MatchKind, pub pos: SingleLineSpan,