Skip to content

Commit

Permalink
Got rid of serde feature to simplify tests & codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
d0rianb committed Sep 16, 2024
1 parent a8f8463 commit c114601
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ categories = ["parsing", "parser-implementations"]
exclude = ["*.rtf", ".idea"]

[lib]
crate-type = ["cdylib"]
crate-type = ["cdylib", "lib"]

[profile.release]
lto = true
Expand All @@ -23,7 +23,7 @@ debug = true

[dependencies]
derivative = "2.2.0"
serde = { version = "1.0", optional = true, features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }

#[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"
Expand Down
1 change: 1 addition & 0 deletions examples/bench.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::time::Instant;

extern crate rtf_parser;
use rtf_parser::{Lexer, Parser, StyleSheet};

fn main() {
Expand Down
1 change: 0 additions & 1 deletion examples/load_file.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate rtf_parser;
use rtf_parser::{Lexer, Parser, StyleSheet};

fn main() {
Expand Down
2 changes: 0 additions & 2 deletions src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use std::error::Error;
use std::fs;
use std::io::Read;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use wasm_bindgen::prelude::wasm_bindgen;

use crate::header::RtfHeader;
Expand Down
26 changes: 9 additions & 17 deletions src/header.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::collections::HashMap;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use tsify::Tsify;
use wasm_bindgen::prelude::wasm_bindgen;

Expand All @@ -26,8 +24,7 @@ pub type StyleRef = u16;
pub type StyleSheet = HashMap<StyleRef, Style>;

/// Style for the StyleSheet
#[derive(Hash, Default, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Hash, Default, Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct Style {
/// The style attributes
painter: Painter,
Expand All @@ -36,27 +33,24 @@ pub struct Style {
}

/// Information about the document, including references to fonts & styles
#[derive(Default, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize, Tsify))]
#[cfg_attr(all(feature = "serde"), tsify(into_wasm_abi, from_wasm_abi))]
#[derive(Default, Debug, Clone, PartialEq, Deserialize, Serialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct RtfHeader {
pub character_set: CharacterSet,
pub font_table: FontTable,
pub color_table: ColorTable,
pub stylesheet: StyleSheet,
}

#[derive(Hash, Default, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Hash, Default, Clone, Debug, PartialEq, Deserialize, Serialize)]
#[wasm_bindgen(getter_with_clone)]
pub struct Font {
pub name: String,
pub character_set: u8,
pub font_family: FontFamily,
}

#[derive(Hash, Default, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Hash, Default, Clone, Debug, PartialEq, Deserialize, Serialize)]
#[wasm_bindgen]
pub struct Color {
pub red: u8,
Expand All @@ -65,9 +59,8 @@ pub struct Color {
}

#[allow(dead_code)]
#[derive(Debug, PartialEq, Default, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize, Tsify))]
#[cfg_attr(all(feature = "serde", target_arch = "wasm32"), tsify(into_wasm_abi, from_wasm_abi))]
#[derive(Debug, PartialEq, Default, Clone, Hash, Deserialize, Serialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub enum CharacterSet {
#[default]
Ansi,
Expand All @@ -88,9 +81,8 @@ impl CharacterSet {
}

#[allow(dead_code)]
#[derive(Debug, PartialEq, Hash, Clone, Default)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize, Tsify))]
#[cfg_attr(all(feature = "serde"), tsify(into_wasm_abi, from_wasm_abi))]
#[derive(Debug, PartialEq, Hash, Clone, Default, Deserialize, Serialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub enum FontFamily {
#[default]
Nil,
Expand Down
21 changes: 7 additions & 14 deletions src/paragraph.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/// Define the paragraph related structs and enums

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use tsify::Tsify;
use wasm_bindgen::prelude::wasm_bindgen;

use crate::tokens::ControlWord;

#[derive(Debug, Default, Clone, Copy, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Debug, Default, Clone, Copy, PartialEq, Hash, Deserialize, Serialize)]
#[wasm_bindgen]
pub struct Paragraph {
pub alignment: Alignment,
Expand All @@ -19,9 +16,8 @@ pub struct Paragraph {
}

/// Alignement of a paragraph (left, right, center, justify)
#[derive(Debug, Default, Clone, Copy, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize, Tsify))]
#[cfg_attr(all(feature = "serde"), tsify(into_wasm_abi, from_wasm_abi))]
#[derive(Debug, Default, Clone, Copy, PartialEq, Hash, Deserialize, Serialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub enum Alignment {
#[default]
LeftAligned, // \ql
Expand All @@ -43,8 +39,7 @@ impl From<&ControlWord<'_>> for Alignment {
}

/// The vertical margin before / after a block of text
#[derive(Debug, Default, Clone, Copy, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Debug, Default, Clone, Copy, PartialEq, Hash, Deserialize, Serialize)]
#[wasm_bindgen]
pub struct Spacing {
pub before: i32,
Expand All @@ -53,9 +48,8 @@ pub struct Spacing {
pub line_multiplier: i32,
}

#[derive(Default, Debug, Clone, Copy, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize, Tsify))]
#[cfg_attr(all(feature = "serde"), tsify(into_wasm_abi, from_wasm_abi))]
#[derive(Default, Debug, Clone, Copy, PartialEq, Hash, Deserialize, Serialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub enum SpaceBetweenLine {
Value(i32),
#[default]
Expand All @@ -78,8 +72,7 @@ impl From<i32> for SpaceBetweenLine {
}

// This struct can not be an enum because left-indent and right-ident can both be defined at the same time
#[derive(Default, Debug, Clone, Copy, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Default, Debug, Clone, Copy, PartialEq, Hash, Deserialize, Serialize)]
#[wasm_bindgen]
pub struct Indentation {
pub left: i32,
Expand Down
10 changes: 3 additions & 7 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::collections::HashMap;
use std::{fmt, mem};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use derivative::Derivative;
use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::wasm_bindgen;

use crate::document::RtfDocument;
Expand All @@ -22,17 +20,15 @@ macro_rules! header_control_word {
};
}

#[derive(Debug, Default, PartialEq, Clone)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
#[wasm_bindgen(getter_with_clone)]
pub struct StyleBlock {
pub painter: Painter,
pub paragraph: Paragraph,
pub text: String,
}

#[derive(Derivative, Debug, Clone, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Derivative, Debug, Clone, PartialEq, Hash, Deserialize, Serialize)]
#[derivative(Default)]
#[wasm_bindgen]
pub struct Painter {
Expand Down

0 comments on commit c114601

Please sign in to comment.