From 4ffcdffca6262b857e365cc7617cc78060cbfb16 Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Mon, 8 Aug 2022 00:59:17 +0200 Subject: [PATCH] Hide `Clone` implementations behind crate feature --- Cargo.toml | 1 + src/arena.rs | 4 ++-- src/lib.rs | 21 +++++++++++++++------ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ed3ae954c8..d7f95e6944 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 7f1f117e8e..d21a786cb5 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -161,7 +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. -#[derive(Clone)] +#[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))] @@ -413,7 +413,7 @@ mod tests { /// /// `UniqueArena` is similar to [`Arena`]: If `Arena` is vector-like, /// `UniqueArena` is `HashSet`-like. -#[derive(Clone)] +#[cfg_attr(feature = "clone", derive(Clone))] pub struct UniqueArena { set: IndexSet, diff --git a/src/lib.rs b/src/lib.rs index 31d44429dd..bb8f391aae 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 @@ -556,7 +559,8 @@ pub enum ImageClass { } /// A data type declared in the module. -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[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))] @@ -568,7 +572,8 @@ pub struct Type { } /// Enum with additional information, depending on the kind of type. -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[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))] @@ -744,7 +749,8 @@ pub enum TypeInner { } /// Constant value. -#[derive(Clone, Debug, PartialEq)] +#[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))] @@ -1582,7 +1588,8 @@ pub struct FunctionResult { } /// A function defined in the module. -#[derive(Clone, Debug, Default)] +#[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))] @@ -1646,7 +1653,8 @@ pub struct Function { /// [`Location`]: Binding::Location /// [`function`]: EntryPoint::function /// [`stage`]: EntryPoint::stage -#[derive(Clone, Debug)] +#[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))] @@ -1676,7 +1684,8 @@ pub struct EntryPoint { /// Alternatively, you can load an existing shader using one of the [available front ends][front]. /// /// When finished, you can export modules using one of the [available backends][back]. -#[derive(Clone, Debug, Default)] +#[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))]