Skip to content

Commit 2772fa9

Browse files
Jonathan Woollett-Lightroypat
authored andcommitted
Added serde feature
Signed-off-by: Jonathan Woollett-Light <jcawl@amazon.co.uk>
1 parent ca53140 commit 2772fa9

File tree

5 files changed

+7
-0
lines changed

5 files changed

+7
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ edition = "2018"
1212
[dependencies]
1313
libc = "0.2.39"
1414
thiserror = "2.0"
15+
serde = { version = "1.0.137", optional = true, features = ["derive"] }

src/address_allocator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::{AllocPolicy, Constraint, Error, RangeInclusive, Result};
2222
/// The `AddressAllocator` manages an address space by exporting functionality to reserve and
2323
/// free address ranges based on a user defined [Allocation Policy](enum.AllocPolicy.html).
2424
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
25+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2526
pub struct AddressAllocator {
2627
// Address space that we want to manage.
2728
address_space: RangeInclusive,

src/allocation_engine/interval_tree.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub fn align_up(address: u64, alignment: u64) -> Result<u64> {
4141
/// - Allocated -> Free: IntervalTree::free()
4242
/// - * -> None: IntervalTree::delete()
4343
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord)]
44+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4445
pub enum NodeState {
4546
/// Node is free.
4647
Free,
@@ -56,6 +57,7 @@ impl NodeState {
5657

5758
/// Internal tree node to implement interval tree.
5859
#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
60+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5961
pub(crate) struct InnerNode {
6062
/// Interval handled by this node.
6163
key: RangeInclusive,
@@ -490,6 +492,7 @@ fn height(node: &Option<Box<InnerNode>>) -> u64 {
490492

491493
/// An interval tree implementation specialized for VMM memory slots management.
492494
#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
495+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
493496
pub struct IntervalTree {
494497
root: Option<Box<InnerNode>>,
495498
}

src/id_allocator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::collections::BTreeSet;
1818
// O(logN) compared to Vec for example, another benefit is that the entries
1919
// are sorted so we will always use the first available ID.
2020
#[derive(Debug)]
21+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2122
pub struct IdAllocator {
2223
// Beginning of the range of IDs that we want to manage.
2324
range_base: u32,

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ pub type Result<T> = result::Result<T, Error>;
158158
/// ```
159159
// This structure represents the key of the Node object in the interval tree implementation.
160160
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Ord, Debug)]
161+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
161162
pub struct RangeInclusive {
162163
/// Lower boundary of the interval.
163164
start: u64,

0 commit comments

Comments
 (0)