Skip to content

Commit 39f98b1

Browse files
committed
Clean up dyn_any usages
1 parent 7b64c73 commit 39f98b1

File tree

21 files changed

+81
-70
lines changed

21 files changed

+81
-70
lines changed

node-graph/gcore/src/application_io.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl TransformMut for SurfaceFrame {
4949
}
5050
}
5151

52+
#[cfg(feature = "dyn-any")]
5253
unsafe impl StaticType for SurfaceFrame {
5354
type Static = SurfaceFrame;
5455
}
@@ -92,6 +93,7 @@ impl PartialEq for ImageTexture {
9293
}
9394
}
9495

96+
#[cfg(feature = "dyn-any")]
9597
unsafe impl StaticType for ImageTexture {
9698
type Static = ImageTexture;
9799
}
@@ -130,6 +132,7 @@ impl<S: Size> Size for SurfaceHandle<S> {
130132
}
131133
}
132134

135+
#[cfg(feature = "dyn-any")]
133136
unsafe impl<T: 'static> StaticType for SurfaceHandle<T> {
134137
type Static = SurfaceHandle<T>;
135138
}
@@ -140,6 +143,7 @@ pub struct SurfaceHandleFrame<Surface> {
140143
pub transform: DAffine2,
141144
}
142145

146+
#[cfg(feature = "dyn-any")]
143147
unsafe impl<T: 'static> StaticType for SurfaceHandleFrame<T> {
144148
type Static = SurfaceHandleFrame<T>;
145149
}
@@ -319,6 +323,7 @@ impl<T> Debug for EditorApi<T> {
319323
}
320324
}
321325

326+
#[cfg(feature = "dyn-any")]
322327
unsafe impl<T: StaticTypeSized> StaticType for EditorApi<T> {
323328
type Static = EditorApi<T::Static>;
324329
}

node-graph/gcore/src/instances.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ use crate::vector::{InstanceId, VectorData, VectorDataTable};
66
use crate::{AlphaBlending, GraphicElement, GraphicGroup, GraphicGroupTable, RasterFrame};
77

88
use dyn_any::StaticType;
9+
910
use glam::{DAffine2, DVec2};
1011
use std::hash::Hash;
1112

1213
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
13-
pub struct Instances<T>
14-
where
15-
T: Into<GraphicElement> + StaticType + 'static,
16-
{
14+
pub struct Instances<T> {
1715
id: Vec<InstanceId>,
1816
#[serde(alias = "instances")]
1917
instance: Vec<T>,
2018
transform: Vec<DAffine2>,
2119
alpha_blending: Vec<AlphaBlending>,
2220
}
2321

24-
impl<T: Into<GraphicElement> + StaticType + 'static> Instances<T> {
22+
impl<T> Instances<T> {
2523
pub fn new(instance: T) -> Self {
2624
Self {
2725
id: vec![InstanceId::generate()],
@@ -82,13 +80,13 @@ impl<T: Into<GraphicElement> + StaticType + 'static> Instances<T> {
8280
}
8381
}
8482

85-
impl<T: Into<GraphicElement> + Default + Hash + StaticType + 'static> Default for Instances<T> {
83+
impl<T: Default + Hash> Default for Instances<T> {
8684
fn default() -> Self {
8785
Self::new(T::default())
8886
}
8987
}
9088

91-
impl<T: Into<GraphicElement> + Hash + StaticType + 'static> core::hash::Hash for Instances<T> {
89+
impl<T: Hash> core::hash::Hash for Instances<T> {
9290
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
9391
self.id.hash(state);
9492
for instance in &self.instance {
@@ -97,13 +95,14 @@ impl<T: Into<GraphicElement> + Hash + StaticType + 'static> core::hash::Hash for
9795
}
9896
}
9997

100-
impl<T: Into<GraphicElement> + PartialEq + StaticType + 'static> PartialEq for Instances<T> {
98+
impl<T: PartialEq> PartialEq for Instances<T> {
10199
fn eq(&self, other: &Self) -> bool {
102100
self.id == other.id && self.instance.len() == other.instance.len() && { self.instance.iter().zip(other.instance.iter()).all(|(a, b)| a == b) }
103101
}
104102
}
105103

106-
unsafe impl<T: Into<GraphicElement> + StaticType + 'static> dyn_any::StaticType for Instances<T> {
104+
#[cfg(feature = "dyn-any")]
105+
unsafe impl<T: StaticType + 'static> StaticType for Instances<T> {
107106
type Static = Instances<T>;
108107
}
109108

@@ -226,8 +225,6 @@ impl<P: Pixel> TransformMut for InstanceMut<'_, Image<P>> {
226225
// IMAGE FRAME TABLE
227226
impl<P: Pixel> Transform for ImageFrameTable<P>
228227
where
229-
P: dyn_any::StaticType,
230-
P::Static: Pixel,
231228
GraphicElement: From<Image<P>>,
232229
{
233230
fn transform(&self) -> DAffine2 {
@@ -236,8 +233,6 @@ where
236233
}
237234
impl<P: Pixel> TransformMut for ImageFrameTable<P>
238235
where
239-
P: dyn_any::StaticType,
240-
P::Static: Pixel,
241236
GraphicElement: From<Image<P>>,
242237
{
243238
fn transform_mut(&mut self) -> &mut DAffine2 {

node-graph/gcore/src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ pub mod registry;
5151

5252
pub use context::*;
5353
use core::any::TypeId;
54+
use core::pin::Pin;
55+
pub use dyn_any::{StaticTypeSized, WasmNotSend, WasmNotSync};
5456
pub use memo::MemoHash;
5557
pub use raster::Color;
5658
pub use types::Cow;
@@ -149,10 +151,6 @@ impl<'i, I: 'i, O: 'i, N: Node<'i, I, Output = O> + ?Sized> Node<'i, I> for allo
149151
}
150152
}
151153

152-
use dyn_any::StaticTypeSized;
153-
154-
use core::pin::Pin;
155-
156154
#[cfg(feature = "alloc")]
157155
impl<'i, I, O: 'i> Node<'i, I> for Pin<Box<dyn Node<'i, I, Output = O> + 'i>> {
158156
type Output = O;
@@ -173,5 +171,3 @@ pub use crate::application_io::{SurfaceFrame, SurfaceId};
173171
pub type WasmSurfaceHandle = application_io::SurfaceHandle<web_sys::HtmlCanvasElement>;
174172
#[cfg(feature = "wasm")]
175173
pub type WasmSurfaceHandleFrame = application_io::SurfaceHandleFrame<web_sys::HtmlCanvasElement>;
176-
177-
pub use dyn_any::{WasmNotSend, WasmNotSync};

node-graph/gcore/src/raster/adjustments.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,6 @@ impl Adjust<Color> for GradientStops {
734734
}
735735
impl<P: Pixel> Adjust<P> for ImageFrameTable<P>
736736
where
737-
P: dyn_any::StaticType,
738-
P::Static: Pixel,
739737
GraphicElement: From<Image<P>>,
740738
{
741739
fn adjust(&mut self, map_fn: impl Fn(&P) -> P) {
@@ -1382,8 +1380,6 @@ impl MultiplyAlpha for GraphicGroupTable {
13821380
}
13831381
impl<P: Pixel> MultiplyAlpha for ImageFrameTable<P>
13841382
where
1385-
P: dyn_any::StaticType,
1386-
P::Static: Pixel,
13871383
GraphicElement: From<Image<P>>,
13881384
{
13891385
fn multiply_alpha(&mut self, factor: f64) {

node-graph/gcore/src/raster/bbox.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use dyn_any::DynAny;
2+
23
use glam::{DAffine2, DVec2};
34

45
#[cfg_attr(not(target_arch = "spirv"), derive(Debug))]

node-graph/gcore/src/raster/brush_cache.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use crate::vector::brush_stroke::BrushStroke;
44
use crate::vector::brush_stroke::BrushStyle;
55
use crate::Color;
66

7-
use core::hash::Hash;
87
use dyn_any::DynAny;
8+
9+
use core::hash::Hash;
910
use std::collections::HashMap;
1011
use std::sync::Arc;
1112
use std::sync::Mutex;

node-graph/gcore/src/raster/curve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pub struct ValueMapperNode<C> {
176176
lut: Vec<C>,
177177
}
178178

179+
#[cfg(feature = "dyn-any")]
179180
unsafe impl<C: StaticTypeSized> StaticType for ValueMapperNode<C> {
180181
type Static = ValueMapperNode<C::Static>;
181182
}

node-graph/gcore/src/raster/image.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use super::discrete_srgb::float_to_srgb_u8;
22
use super::Color;
3+
use crate::instances::Instances;
4+
use crate::transform::TransformMut;
35
use crate::GraphicElement;
4-
use crate::{instances::Instances, transform::TransformMut};
6+
57
use alloc::vec::Vec;
68
use core::hash::{Hash, Hasher};
79
use dyn_any::StaticType;
@@ -68,6 +70,7 @@ impl<P: Pixel + Debug> Debug for Image<P> {
6870
}
6971
}
7072

73+
#[cfg(feature = "dyn-any")]
7174
unsafe impl<P> StaticType for Image<P>
7275
where
7376
P: dyn_any::StaticTypeSized + Pixel,
@@ -235,6 +238,8 @@ pub fn migrate_image_frame<'de, D: serde::Deserializer<'de>>(deserializer: D) ->
235238
}
236239
}
237240
}
241+
242+
#[cfg(feature = "dyn-any")]
238243
unsafe impl<P> StaticType for ImageFrame<P>
239244
where
240245
P: dyn_any::StaticTypeSized + Pixel,
@@ -286,8 +291,7 @@ impl<P: Debug + Copy + Pixel> Sample for Image<P> {
286291

287292
impl<P> Sample for ImageFrameTable<P>
288293
where
289-
P: Debug + Copy + Pixel + dyn_any::StaticType,
290-
P::Static: Pixel,
294+
P: Debug + Copy + Pixel,
291295
GraphicElement: From<Image<P>>,
292296
{
293297
type Pixel = P;
@@ -307,8 +311,7 @@ where
307311

308312
impl<P> Bitmap for ImageFrameTable<P>
309313
where
310-
P: Copy + Pixel + dyn_any::StaticType,
311-
P::Static: Pixel,
314+
P: Copy + Pixel,
312315
GraphicElement: From<Image<P>>,
313316
{
314317
type Pixel = P;
@@ -334,8 +337,7 @@ where
334337

335338
impl<P> BitmapMut for ImageFrameTable<P>
336339
where
337-
P: Copy + Pixel + dyn_any::StaticType,
338-
P::Static: Pixel,
340+
P: Copy + Pixel,
339341
GraphicElement: From<Image<P>>,
340342
{
341343
fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut Self::Pixel> {

node-graph/gcore/src/registry.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
use crate::transform::Footprint;
2+
use crate::Node;
3+
use crate::NodeIO;
4+
use crate::NodeIOTypes;
5+
use crate::WasmNotSend;
6+
7+
use dyn_any::{DynAny, StaticType};
8+
19
use std::collections::HashMap;
10+
use std::marker::PhantomData;
211
use std::ops::Deref;
312
use std::pin::Pin;
413
use std::sync::{LazyLock, Mutex};
514

6-
use dyn_any::DynAny;
7-
8-
use crate::transform::Footprint;
9-
use crate::NodeIO;
10-
use crate::NodeIOTypes;
11-
1215
pub mod types {
1316
/// 0% - 100%
1417
pub type Percentage = f64;
@@ -153,11 +156,6 @@ impl NodeContainer {
153156
}
154157
}
155158

156-
use crate::Node;
157-
use crate::WasmNotSend;
158-
use dyn_any::StaticType;
159-
use std::marker::PhantomData;
160-
161159
/// Boxes the input and downcasts the output.
162160
/// Wraps around a node taking Box<dyn DynAny> and returning Box<dyn DynAny>
163161
#[derive(Clone)]
@@ -166,7 +164,11 @@ pub struct DowncastBothNode<I, O> {
166164
_i: PhantomData<I>,
167165
_o: PhantomData<O>,
168166
}
169-
impl<'input, O: 'input + StaticType + WasmNotSend, I: 'input + StaticType + WasmNotSend> Node<'input, I> for DowncastBothNode<I, O> {
167+
impl<'input, O, I> Node<'input, I> for DowncastBothNode<I, O>
168+
where
169+
O: 'input + StaticType + WasmNotSend,
170+
I: 'input + StaticType + WasmNotSend,
171+
{
170172
type Output = DynFuture<'input, O>;
171173
#[inline]
172174
fn eval(&'input self, input: I) -> Self::Output {
@@ -234,9 +236,11 @@ pub struct DynAnyNode<I, O, Node> {
234236
_o: PhantomData<O>,
235237
}
236238

237-
impl<'input, _I: 'input + StaticType + WasmNotSend, _O: 'input + StaticType + WasmNotSend, N: 'input> Node<'input, Any<'input>> for DynAnyNode<_I, _O, N>
239+
impl<'input, _I, _O, N> Node<'input, Any<'input>> for DynAnyNode<_I, _O, N>
238240
where
239-
N: Node<'input, _I, Output = DynFuture<'input, _O>>,
241+
_I: 'input + dyn_any::StaticType + WasmNotSend,
242+
_O: 'input + dyn_any::StaticType + WasmNotSend,
243+
N: 'input + Node<'input, _I, Output = DynFuture<'input, _O>>,
240244
{
241245
type Output = FutureAny<'input>;
242246
#[inline]
@@ -275,9 +279,11 @@ where
275279
self.node.serialize()
276280
}
277281
}
278-
impl<'input, _I: 'input + StaticType, _O: 'input + StaticType, N: 'input> DynAnyNode<_I, _O, N>
282+
impl<'input, _I, _O, N> DynAnyNode<_I, _O, N>
279283
where
280-
N: Node<'input, _I, Output = DynFuture<'input, _O>>,
284+
_I: 'input + dyn_any::StaticType,
285+
_O: 'input + dyn_any::StaticType,
286+
N: 'input + Node<'input, _I, Output = DynFuture<'input, _O>>,
281287
{
282288
pub const fn new(node: N) -> Self {
283289
Self {

node-graph/gcore/src/types.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use core::any::TypeId;
22

33
#[cfg(not(feature = "std"))]
44
pub use alloc::borrow::Cow;
5-
use dyn_any::StaticType;
65
#[cfg(feature = "std")]
76
pub use std::borrow::Cow;
87

@@ -205,7 +204,8 @@ impl Default for Type {
205204
}
206205
}
207206

208-
unsafe impl StaticType for Type {
207+
#[cfg(feature = "dyn-any")]
208+
unsafe impl dyn_any::StaticType for Type {
209209
type Static = Self;
210210
}
211211

@@ -254,7 +254,7 @@ impl Type {
254254
}
255255

256256
impl Type {
257-
pub fn new<T: StaticType + Sized>() -> Self {
257+
pub fn new<T: dyn_any::StaticType + Sized>() -> Self {
258258
Self::Concrete(TypeDescriptor {
259259
id: Some(TypeId::of::<T::Static>()),
260260
name: Cow::Borrowed(core::any::type_name::<T::Static>()),
@@ -263,6 +263,7 @@ impl Type {
263263
align: core::mem::align_of::<T>(),
264264
})
265265
}
266+
266267
pub fn size(&self) -> Option<usize> {
267268
match self {
268269
Self::Generic(_) => None,

node-graph/gcore/src/uuid.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use dyn_any::DynAny;
21
pub use uuid_generation::*;
32

3+
use dyn_any::DynAny;
4+
45
#[derive(Clone, Copy, serde::Serialize, serde::Deserialize, specta::Type)]
56
pub struct Uuid(
67
#[serde(with = "u64_string")]

node-graph/gcore/src/vector/brush_stroke.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::raster::BlendMode;
33
use crate::Color;
44

55
use dyn_any::DynAny;
6+
67
use glam::DVec2;
78
use std::hash::{Hash, Hasher};
89

node-graph/gcore/src/vector/style.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::renderer::format_transform_matrix;
55
use crate::Color;
66

77
use dyn_any::DynAny;
8+
89
use glam::{DAffine2, DVec2};
910
use std::fmt::{self, Display, Write};
1011

node-graph/gpu-executor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use dyn_any::{StaticType, StaticTypeSized};
21
use graphene_core::raster::{color::RGBA16F, Image, Pixel, SRGBA8};
32
use graphene_core::*;
43

54
use bytemuck::{Pod, Zeroable};
5+
use dyn_any::{StaticType, StaticTypeSized};
66
use glam::UVec3;
77
use std::borrow::Cow;
88

0 commit comments

Comments
 (0)