From 9477d75a8e9b0d44406a6c491646a51fcfeb720a Mon Sep 17 00:00:00 2001 From: Corwin Date: Sat, 19 Oct 2024 15:06:13 +0100 Subject: [PATCH 1/4] optional serde support in agb-fixnum --- agb-fixnum/Cargo.toml | 4 ++++ agb-fixnum/src/lib.rs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/agb-fixnum/Cargo.toml b/agb-fixnum/Cargo.toml index d434d870b..0238465b8 100644 --- a/agb-fixnum/Cargo.toml +++ b/agb-fixnum/Cargo.toml @@ -7,6 +7,10 @@ description = "Library for abstracting over fixed precision numbers. Designed fo repository = "https://github.com/agbrs/agb" keywords = ["no-std", "no-std::no-alloc"] +[features] +serde = ["dep:serde"] + [dependencies] agb_macros = { version = "0.21.1", path = "../agb-macros" } num-traits = { version = "0.2", default-features = false } +serde = { version = "1", features = ["derive"], optional = true } diff --git a/agb-fixnum/src/lib.rs b/agb-fixnum/src/lib.rs index 499c0d214..c95cbf104 100644 --- a/agb-fixnum/src/lib.rs +++ b/agb-fixnum/src/lib.rs @@ -122,6 +122,7 @@ fixed_width_unsigned_integer_impl!(u32, optimised_64_bit); /// A fixed point number represented using `I` with `N` bits of fractional precision #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(transparent)] pub struct Num(I); @@ -649,6 +650,7 @@ impl Debug for Num { /// A vector of two points: (x, y) represented by integers or fixed point numbers #[derive(Clone, Copy, PartialEq, Eq, Debug, Default, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Vector2D { /// The x coordinate pub x: T, @@ -897,6 +899,7 @@ impl From> for Vector2 } #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] /// A rectangle with a position in 2d space and a 2d size pub struct Rect { /// The position of the rectangle From c3ec6a187fbd41619c4a8b7b77f1f5d82b692a4a Mon Sep 17 00:00:00 2001 From: Corwin Date: Sat, 19 Oct 2024 15:10:51 +0100 Subject: [PATCH 2/4] disable std default-feature --- agb-fixnum/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agb-fixnum/Cargo.toml b/agb-fixnum/Cargo.toml index 0238465b8..207c27bb6 100644 --- a/agb-fixnum/Cargo.toml +++ b/agb-fixnum/Cargo.toml @@ -13,4 +13,4 @@ serde = ["dep:serde"] [dependencies] agb_macros = { version = "0.21.1", path = "../agb-macros" } num-traits = { version = "0.2", default-features = false } -serde = { version = "1", features = ["derive"], optional = true } +serde = { version = "1", features = ["derive"], default-features = false, optional = true } From 34a289f41dfc4592f59a9fcf32204eb6cbb5dd2b Mon Sep 17 00:00:00 2001 From: Corwin Date: Tue, 14 Jan 2025 22:27:45 +0000 Subject: [PATCH 3/4] feature flag to enable serde for dependencies --- agb/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/agb/Cargo.toml b/agb/Cargo.toml index 6984418c3..20ad659e4 100644 --- a/agb/Cargo.toml +++ b/agb/Cargo.toml @@ -15,6 +15,7 @@ default = ["backtrace", "testing"] backtrace = ["testing", "dep:qrcodegen-no-heap"] testing = [] multiboot = [] +serde = ["agb_fixnum/serde", "agb_hashmap/serde"] [dependencies] bitflags = "2" From 9ff8a120a69cf89c71be68a947dc8ea9b6dd9028 Mon Sep 17 00:00:00 2001 From: Corwin Date: Tue, 14 Jan 2025 22:27:52 +0000 Subject: [PATCH 4/4] add changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1570d154a..240642d18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Optional serde support for agb-hashmap via the `serde` feature flag +- Optional serde support for agb-hashmap and agb-fixnum via the `serde` feature flag. The flag is also exposed in the agb crate. - Added `set_background_palette` to be able to set a single background palette. ### Changed