diff --git a/Cargo.toml b/Cargo.toml index c38ff67ad..5a6d62805 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ panic = "abort" [features] default = [] +clone = [] dot-out = [] glsl-in = ["pp-rs"] glsl-validate = [] diff --git a/src/arena.rs b/src/arena.rs index 1f970524e..d21a786cb 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -161,6 +161,7 @@ impl Iterator for Range { /// Adding new items to the arena produces a strongly-typed [`Handle`]. /// The arena can be indexed using the given handle to obtain /// a reference to the stored item. +#[cfg_attr(feature = "clone", derive(Clone))] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "serialize", serde(transparent))] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] @@ -412,6 +413,7 @@ mod tests { /// /// `UniqueArena` is similar to [`Arena`]: If `Arena` is vector-like, /// `UniqueArena` is `HashSet`-like. +#[cfg_attr(feature = "clone", derive(Clone))] pub struct UniqueArena { set: IndexSet, diff --git a/src/lib.rs b/src/lib.rs index 107534c8b..5db2a397d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,9 @@ with optional span info, representing a series of statements executed in order. `EntryPoint`s or `Function` is a `Block`, and `Statement` has a [`Block`][Statement::Block] variant. +If the `clone` feature is enabled, [`Arena`], [`UniqueArena`], [`Type`], [`TypeInner`], +[`Constant`], [`Function`], [`EntryPoint`] and [`Module`] can be cloned. + ## Arenas To improve translator performance and reduce memory usage, most structures are @@ -558,6 +561,7 @@ pub enum ImageClass { /// A data type declared in the module. #[derive(Debug, Eq, Hash, PartialEq)] +#[cfg_attr(feature = "clone", derive(Clone))] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] @@ -570,6 +574,7 @@ pub struct Type { /// Enum with additional information, depending on the kind of type. #[derive(Debug, Eq, Hash, PartialEq)] +#[cfg_attr(feature = "clone", derive(Clone))] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] @@ -746,6 +751,7 @@ pub enum TypeInner { /// Constant value. #[derive(Debug, PartialEq)] +#[cfg_attr(feature = "clone", derive(Clone))] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] @@ -1585,6 +1591,7 @@ pub struct FunctionResult { /// A function defined in the module. #[derive(Debug, Default)] +#[cfg_attr(feature = "clone", derive(Clone))] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] @@ -1649,6 +1656,7 @@ pub struct Function { /// [`function`]: EntryPoint::function /// [`stage`]: EntryPoint::stage #[derive(Debug)] +#[cfg_attr(feature = "clone", derive(Clone))] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] @@ -1679,6 +1687,7 @@ pub struct EntryPoint { /// /// When finished, you can export modules using one of the [available backends][back]. #[derive(Debug, Default)] +#[cfg_attr(feature = "clone", derive(Clone))] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))]