Skip to content

Commit dc02d9a

Browse files
committed
Clean up dyn_any usages
1 parent 9ae6562 commit dc02d9a

File tree

21 files changed

+76
-67
lines changed

21 files changed

+76
-67
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
}
@@ -90,6 +91,7 @@ impl PartialEq for ImageTexture {
9091
}
9192
}
9293

94+
#[cfg(feature = "dyn-any")]
9395
unsafe impl StaticType for ImageTexture {
9496
type Static = ImageTexture;
9597
}
@@ -128,6 +130,7 @@ impl<S: Size> Size for SurfaceHandle<S> {
128130
}
129131
}
130132

133+
#[cfg(feature = "dyn-any")]
131134
unsafe impl<T: 'static> StaticType for SurfaceHandle<T> {
132135
type Static = SurfaceHandle<T>;
133136
}
@@ -138,6 +141,7 @@ pub struct SurfaceHandleFrame<Surface> {
138141
pub transform: DAffine2,
139142
}
140143

144+
#[cfg(feature = "dyn-any")]
141145
unsafe impl<T: 'static> StaticType for SurfaceHandleFrame<T> {
142146
type Static = SurfaceHandleFrame<T>;
143147
}
@@ -317,6 +321,7 @@ impl<T> Debug for EditorApi<T> {
317321
}
318322
}
319323

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

node-graph/gcore/src/instances.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ 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>,
@@ -23,7 +21,7 @@ where
2321
alpha_blending: Vec<AlphaBlending>,
2422
}
2523

26-
impl<T: Into<GraphicElement> + StaticType + 'static> Instances<T> {
24+
impl<T> Instances<T> {
2725
pub fn new(instance: T) -> Self {
2826
Self {
2927
id: vec![InstanceId::generate()],
@@ -84,13 +82,13 @@ impl<T: Into<GraphicElement> + StaticType + 'static> Instances<T> {
8482
}
8583
}
8684

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

93-
impl<T: Into<GraphicElement> + Hash + StaticType + 'static> core::hash::Hash for Instances<T> {
91+
impl<T: Hash> core::hash::Hash for Instances<T> {
9492
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
9593
self.id.hash(state);
9694
for instance in &self.instance {
@@ -99,13 +97,14 @@ impl<T: Into<GraphicElement> + Hash + StaticType + 'static> core::hash::Hash for
9997
}
10098
}
10199

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

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

@@ -235,8 +234,6 @@ impl<P: Pixel> TransformMut for InstanceMut<'_, Image<P>> {
235234
// IMAGE FRAME TABLE
236235
impl<P: Pixel> Transform for ImageFrameTable<P>
237236
where
238-
P: dyn_any::StaticType,
239-
P::Static: Pixel,
240237
GraphicElement: From<Image<P>>,
241238
{
242239
fn transform(&self) -> DAffine2 {
@@ -245,8 +242,6 @@ where
245242
}
246243
impl<P: Pixel> TransformMut for ImageFrameTable<P>
247244
where
248-
P: dyn_any::StaticType,
249-
P::Static: Pixel,
250245
GraphicElement: From<Image<P>>,
251246
{
252247
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;
@@ -148,10 +150,6 @@ impl<'i, I: 'i, O: 'i, N: Node<'i, I, Output = O> + ?Sized> Node<'i, I> for allo
148150
}
149151
}
150152

151-
use dyn_any::StaticTypeSized;
152-
153-
use core::pin::Pin;
154-
155153
#[cfg(feature = "alloc")]
156154
impl<'i, I, O: 'i> Node<'i, I> for Pin<Box<dyn Node<'i, I, Output = O> + 'i>> {
157155
type Output = O;
@@ -172,5 +170,3 @@ pub use crate::application_io::{SurfaceFrame, SurfaceId};
172170
pub type WasmSurfaceHandle = application_io::SurfaceHandle<web_sys::HtmlCanvasElement>;
173171
#[cfg(feature = "wasm")]
174172
pub type WasmSurfaceHandleFrame = application_io::SurfaceHandleFrame<web_sys::HtmlCanvasElement>;
175-
176-
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: 10 additions & 8 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, transform::TransformMut};
4-
use crate::{AlphaBlending, GraphicElement};
3+
use crate::instances::Instances;
4+
use crate::transform::TransformMut;
5+
use crate::AlphaBlending;
6+
use crate::GraphicElement;
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,
@@ -302,8 +307,7 @@ impl<P: Debug + Copy + Pixel> Sample for Image<P> {
302307

303308
impl<P> Sample for ImageFrameTable<P>
304309
where
305-
P: Debug + Copy + Pixel + dyn_any::StaticType,
306-
P::Static: Pixel,
310+
P: Debug + Copy + Pixel,
307311
GraphicElement: From<Image<P>>,
308312
{
309313
type Pixel = P;
@@ -323,8 +327,7 @@ where
323327

324328
impl<P> Bitmap for ImageFrameTable<P>
325329
where
326-
P: Copy + Pixel + dyn_any::StaticType,
327-
P::Static: Pixel,
330+
P: Copy + Pixel,
328331
GraphicElement: From<Image<P>>,
329332
{
330333
type Pixel = P;
@@ -350,8 +353,7 @@ where
350353

351354
impl<P> BitmapMut for ImageFrameTable<P>
352355
where
353-
P: Copy + Pixel + dyn_any::StaticType,
354-
P::Static: Pixel,
356+
P: Copy + Pixel,
355357
GraphicElement: From<Image<P>>,
356358
{
357359
fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut Self::Pixel> {

node-graph/gcore/src/registry.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::transform::Footprint;
2-
use crate::{NodeIO, NodeIOTypes, Type};
2+
use crate::{Node, NodeIO, NodeIOTypes, Type, WasmNotSend};
33

4-
use dyn_any::DynAny;
4+
use dyn_any::{DynAny, StaticType};
55

66
use std::collections::HashMap;
7+
use std::marker::PhantomData;
78
use std::ops::Deref;
89
use std::pin::Pin;
910
use std::sync::{LazyLock, Mutex};
@@ -153,11 +154,6 @@ impl NodeContainer {
153154
}
154155
}
155156

156-
use crate::Node;
157-
use crate::WasmNotSend;
158-
use dyn_any::StaticType;
159-
use std::marker::PhantomData;
160-
161157
/// Boxes the input and downcasts the output.
162158
/// Wraps around a node taking Box<dyn DynAny> and returning Box<dyn DynAny>
163159
#[derive(Clone)]
@@ -166,7 +162,11 @@ pub struct DowncastBothNode<I, O> {
166162
_i: PhantomData<I>,
167163
_o: PhantomData<O>,
168164
}
169-
impl<'input, O: 'input + StaticType + WasmNotSend, I: 'input + StaticType + WasmNotSend> Node<'input, I> for DowncastBothNode<I, O> {
165+
impl<'input, O, I> Node<'input, I> for DowncastBothNode<I, O>
166+
where
167+
O: 'input + StaticType + WasmNotSend,
168+
I: 'input + StaticType + WasmNotSend,
169+
{
170170
type Output = DynFuture<'input, O>;
171171
#[inline]
172172
fn eval(&'input self, input: I) -> Self::Output {
@@ -234,9 +234,11 @@ pub struct DynAnyNode<I, O, Node> {
234234
_o: PhantomData<O>,
235235
}
236236

237-
impl<'input, _I: 'input + StaticType + WasmNotSend, _O: 'input + StaticType + WasmNotSend, N: 'input> Node<'input, Any<'input>> for DynAnyNode<_I, _O, N>
237+
impl<'input, _I, _O, N> Node<'input, Any<'input>> for DynAnyNode<_I, _O, N>
238238
where
239-
N: Node<'input, _I, Output = DynFuture<'input, _O>>,
239+
_I: 'input + dyn_any::StaticType + WasmNotSend,
240+
_O: 'input + dyn_any::StaticType + WasmNotSend,
241+
N: 'input + Node<'input, _I, Output = DynFuture<'input, _O>>,
240242
{
241243
type Output = FutureAny<'input>;
242244
#[inline]
@@ -275,9 +277,11 @@ where
275277
self.node.serialize()
276278
}
277279
}
278-
impl<'input, _I: 'input + StaticType, _O: 'input + StaticType, N: 'input> DynAnyNode<_I, _O, N>
280+
impl<'input, _I, _O, N> DynAnyNode<_I, _O, N>
279281
where
280-
N: Node<'input, _I, Output = DynFuture<'input, _O>>,
282+
_I: 'input + dyn_any::StaticType,
283+
_O: 'input + dyn_any::StaticType,
284+
N: 'input + Node<'input, _I, Output = DynFuture<'input, _O>>,
281285
{
282286
pub const fn new(node: N) -> Self {
283287
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

@@ -220,7 +219,8 @@ impl Default for Type {
220219
}
221220
}
222221

223-
unsafe impl StaticType for Type {
222+
#[cfg(feature = "dyn-any")]
223+
unsafe impl dyn_any::StaticType for Type {
224224
type Static = Self;
225225
}
226226

@@ -269,7 +269,7 @@ impl Type {
269269
}
270270

271271
impl Type {
272-
pub fn new<T: StaticType + Sized>() -> Self {
272+
pub fn new<T: dyn_any::StaticType + Sized>() -> Self {
273273
Self::Concrete(TypeDescriptor {
274274
id: Some(TypeId::of::<T::Static>()),
275275
name: Cow::Borrowed(core::any::type_name::<T::Static>()),
@@ -278,6 +278,7 @@ impl Type {
278278
align: core::mem::align_of::<T>(),
279279
})
280280
}
281+
281282
pub fn size(&self) -> Option<usize> {
282283
match self {
283284
Self::Generic(_) => None,

0 commit comments

Comments
 (0)