Add serde serialization support for the full clif ir
This commit is contained in:
@@ -5,6 +5,9 @@ use alloc::vec::Vec;
|
||||
use core::marker::PhantomData;
|
||||
use core::mem;
|
||||
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A small list of entity references allocated from a pool.
|
||||
///
|
||||
/// An `EntityList<T>` type provides similar functionality to `Vec<T>`, but with some important
|
||||
@@ -59,7 +62,8 @@ use core::mem;
|
||||
///
|
||||
/// The index stored in an `EntityList` points to part 2, the list elements. The value 0 is
|
||||
/// reserved for the empty list which isn't allocated in the vector.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
pub struct EntityList<T: EntityRef + ReservedValue> {
|
||||
index: u32,
|
||||
unused: PhantomData<T>,
|
||||
@@ -77,6 +81,7 @@ impl<T: EntityRef + ReservedValue> Default for EntityList<T> {
|
||||
|
||||
/// A memory pool for storing lists of `T`.
|
||||
#[derive(Clone, Debug)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
pub struct ListPool<T: EntityRef + ReservedValue> {
|
||||
// The main array containing the lists.
|
||||
data: Vec<T>,
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
use core::fmt;
|
||||
use core::mem;
|
||||
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Types that have a reserved value which can't be created any other way.
|
||||
pub trait ReservedValue {
|
||||
/// Create an instance of the reserved value.
|
||||
@@ -20,6 +23,7 @@ pub trait ReservedValue {
|
||||
|
||||
/// Packed representation of `Option<T>`.
|
||||
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
pub struct PackedOption<T: ReservedValue>(T);
|
||||
|
||||
impl<T: ReservedValue> PackedOption<T> {
|
||||
|
||||
@@ -14,6 +14,9 @@ use core::mem;
|
||||
use core::slice;
|
||||
use core::u32;
|
||||
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Trait for extracting keys from values stored in a `SparseMap`.
|
||||
///
|
||||
/// All values stored in a `SparseMap` must keep track of their own key in the map and implement
|
||||
@@ -53,6 +56,7 @@ pub trait SparseMapValue<K> {
|
||||
/// is).
|
||||
/// - `SparseMap` requires the values to implement `SparseMapValue<K>` which means that they must
|
||||
/// contain their own key.
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
pub struct SparseMap<K, V>
|
||||
where
|
||||
K: EntityRef,
|
||||
|
||||
Reference in New Issue
Block a user