aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyose <ayosec@gmail.com>2024-02-11 00:00:00 +0000
committerAyose <ayosec@gmail.com>2024-02-11 00:00:00 +0000
commite1b78c1a65cbd85b7e20e9b35164abc96896ebbb (patch)
treecf3c37e5a1c6a2a7d2486d891b5655698315f3cc
parent5e75fc92bd6bd956873baa8e30d2c14f2fe83a54 (diff)
downloadr-alacritty-e1b78c1a65cbd85b7e20e9b35164abc96896ebbb.tar.gz
r-alacritty-e1b78c1a65cbd85b7e20e9b35164abc96896ebbb.tar.bz2
r-alacritty-e1b78c1a65cbd85b7e20e9b35164abc96896ebbb.zip
Serialize/Deserialize only if the `serde` feature is set.
-rw-r--r--alacritty_terminal/src/graphics/mod.rs21
-rw-r--r--alacritty_terminal/src/term/cell.rs2
2 files changed, 16 insertions, 7 deletions
diff --git a/alacritty_terminal/src/graphics/mod.rs b/alacritty_terminal/src/graphics/mod.rs
index 8ddf31cc..b2b934d0 100644
--- a/alacritty_terminal/src/graphics/mod.rs
+++ b/alacritty_terminal/src/graphics/mod.rs
@@ -8,8 +8,10 @@ use std::fmt::Write;
use std::sync::{Arc, Weak};
use std::{cmp, mem};
-use parking_lot::Mutex;
+#[cfg(feature = "serde")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
+
+use parking_lot::Mutex;
use smallvec::SmallVec;
use crate::event::{Event, EventListener};
@@ -26,7 +28,8 @@ pub const MAX_GRAPHIC_DIMENSIONS: [usize; 2] = [4096, 4096];
const MAX_GRAPHICS_PER_CELL: usize = 20;
/// Unique identifier for every graphic added to a grid.
-#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug, Copy, Hash, PartialOrd, Ord)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[derive(Eq, PartialEq, Clone, Debug, Copy, Hash, PartialOrd, Ord)]
pub struct GraphicId(u64);
/// Reference to a texture stored in the display.
@@ -110,7 +113,8 @@ impl Drop for GraphicCell {
}
}
-#[derive(Deserialize, Serialize)]
+#[cfg(feature = "serde")]
+#[derive(Serialize, Deserialize)]
struct GraphicCellSerde {
texture: GraphicId,
offset_x: u16,
@@ -120,6 +124,7 @@ struct GraphicCellSerde {
tex_cell_height: usize,
}
+#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for GraphicCell {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -148,6 +153,7 @@ impl<'de> Deserialize<'de> for GraphicCell {
}
}
+#[cfg(feature = "serde")]
impl Serialize for GraphicCell {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -175,7 +181,8 @@ impl GraphicCell {
}
/// Specifies the format of the pixel data.
-#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug, Copy)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[derive(Eq, PartialEq, Clone, Debug, Copy)]
pub enum ColorType {
/// 3 bytes per pixel (red, green, blue).
Rgb,
@@ -185,7 +192,8 @@ pub enum ColorType {
}
/// Defines a single graphic read from the PTY.
-#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[derive(Eq, PartialEq, Clone, Debug)]
pub struct GraphicData {
/// Graphics identifier.
pub id: GraphicId,
@@ -247,7 +255,8 @@ impl GraphicData {
}
/// Operation to clear a subregion in an existing graphic.
-#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[derive(Eq, PartialEq, Clone, Debug)]
pub struct ClearSubregion {
/// Graphics identifier.
pub id: GraphicId,
diff --git a/alacritty_terminal/src/term/cell.rs b/alacritty_terminal/src/term/cell.rs
index 6450b235..6b32c781 100644
--- a/alacritty_terminal/src/term/cell.rs
+++ b/alacritty_terminal/src/term/cell.rs
@@ -131,7 +131,7 @@ pub struct CellExtra {
hyperlink: Option<Hyperlink>,
- #[serde(skip_serializing_if = "Option::is_none")]
+ #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
graphics: Option<GraphicsCell>,
}