Skip to content

Commit

Permalink
Add serde
Browse files Browse the repository at this point in the history
  • Loading branch information
anchpop committed Apr 27, 2022
1 parent 2cc8567 commit 62a53f9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/lines.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/positions.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/summary.rs
Original file line number Diff line number Diff line change
@@ -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<u8>),
}

#[derive(Debug)]
#[derive(Serialize, Deserialize, Debug)]
pub struct DiffResult {
pub path: String,
pub language: Option<String>,
Expand Down
9 changes: 5 additions & 4 deletions src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 62a53f9

Please sign in to comment.