@@ -113,6 +113,15 @@ type Dim <T> = <T as Shape>::Dim;
113
113
114
114
// === Shapes for numbers ===
115
115
116
+ impl Shape for i32 {
117
+ type Item = Self ;
118
+ type Dim = U1 ;
119
+
120
+ fn empty ( ) -> Self { 0 }
121
+ fn from_buffer ( buffer : & [ Self :: Item ] ) -> & [ Self ] { buffer }
122
+ fn from_buffer_mut ( buffer : & mut [ Self :: Item ] ) -> & mut [ Self ] { buffer }
123
+ }
124
+
116
125
impl Shape for f32 {
117
126
type Item = Self ;
118
127
type Dim = U1 ;
@@ -289,6 +298,10 @@ Attribute<T, OnSet, OnResize> {
289
298
let logger = bldr. _logger . unwrap_or_else ( default) ;
290
299
Self :: new_from ( buffer, logger, on_set, on_resize)
291
300
}
301
+
302
+ pub fn builder ( ) -> Builder < T > {
303
+ default ( )
304
+ }
292
305
}
293
306
294
307
impl < T : Shape , OnSet , OnResize >
@@ -310,70 +323,64 @@ Attribute<T, OnSet, OnResize> {
310
323
}
311
324
}
312
325
313
- impl < T : Shape >
314
- Attribute < T , NoCallback , NoCallback > {
315
- pub fn builder ( ) -> Builder < T > {
316
- default ( )
317
- }
318
- }
319
326
320
327
321
- // =======================
322
- // === SharedAttribute ===
323
- // =======================
328
+ // // =======================
329
+ // // === SharedAttribute ===
330
+ // // =======================
324
331
325
- // === Definition ===
332
+ // // === Definition ===
326
333
327
- #[ derive( Shrinkwrap ) ]
328
- #[ derive( Derivative ) ]
329
- #[ derivative( Debug ( bound="T:Debug" ) ) ]
330
- pub struct SharedAttribute < T : Shape , OnSet , OnResize > {
331
- pub data : Shared < Attribute < T , OnSet , OnResize > >
332
- }
334
+ // #[derive(Shrinkwrap)]
335
+ // #[derive(Derivative)]
336
+ // #[derivative(Debug(bound="T:Debug"))]
337
+ // pub struct SharedAttribute<T: Shape, OnSet, OnResize> {
338
+ // pub data: Shared<Attribute<T, OnSet, OnResize>>
339
+ // }
333
340
334
- impl < T : Shape , OnSet : Callback0 , OnResize : Callback0 > SharedAttribute < T , OnSet , OnResize > {
335
- pub fn new ( logger : Logger , on_set : OnSet , on_resize : OnResize ) -> Self {
336
- Self :: new_from ( default ( ) , logger, on_set, on_resize)
337
- }
341
+ // impl<T: Shape, OnSet: Callback0, OnResize: Callback0> SharedAttribute<T, OnSet, OnResize> {
342
+ // pub fn new(logger: Logger, on_set: OnSet, on_resize: OnResize) -> Self {
343
+ // Self::new_from(default(), logger, on_set, on_resize)
344
+ // }
338
345
339
- pub fn new_from ( buffer : Vec < T > , logger : Logger , on_set : OnSet , on_resize : OnResize ) -> Self {
340
- let data = Shared :: new ( Attribute :: new_from ( buffer, logger, on_set, on_resize) ) ;
341
- Self { data }
342
- }
346
+ // pub fn new_from(buffer: Vec<T>, logger: Logger, on_set: OnSet, on_resize: OnResize) -> Self {
347
+ // let data = Shared::new(Attribute::new_from(buffer, logger, on_set, on_resize));
348
+ // Self { data }
349
+ // }
343
350
344
- pub fn build ( builder : Builder < T > , on_set : OnSet , on_resize : OnResize ) -> Self {
345
- let data = Shared :: new ( Attribute :: build ( builder, on_set, on_resize) ) ;
346
- Self { data }
347
- }
351
+ // pub fn build(builder: Builder<T>, on_set: OnSet, on_resize: OnResize) -> Self {
352
+ // let data = Shared::new(Attribute::build(builder, on_set, on_resize));
353
+ // Self { data }
354
+ // }
348
355
349
- pub fn builder ( ) -> Builder < T > {
350
- default ( )
351
- }
352
- }
356
+ // pub fn builder() -> Builder<T> {
357
+ // default()
358
+ // }
359
+ // }
353
360
354
- impl < T : Shape , OnSet , OnResize > SharedAttribute < T , OnSet , OnResize > {
355
- pub fn clone_ref ( & self ) -> Self {
356
- Self { data : self . data . clone_ref ( ) }
357
- }
361
+ // impl<T: Shape, OnSet, OnResize> SharedAttribute<T, OnSet, OnResize> {
362
+ // pub fn clone_ref(&self) -> Self {
363
+ // Self { data: self.data.clone_ref() }
364
+ // }
358
365
359
- pub fn len ( & self ) -> usize {
360
- self . data . borrow ( ) . len ( )
361
- }
362
- }
366
+ // pub fn len(&self) -> usize {
367
+ // self.data.borrow().len()
368
+ // }
369
+ // }
363
370
364
- impl < T : AddElementCtx , OnSet , OnResize > SharedAttribute < T , OnSet , OnResize > {
365
- pub fn add_element ( & self ) {
366
- self . data . borrow_mut ( ) . add_element ( )
367
- }
368
- }
371
+ // impl<T: AddElementCtx, OnSet, OnResize> SharedAttribute<T, OnSet, OnResize> {
372
+ // pub fn add_element(&self) {
373
+ // self.data.borrow_mut().add_element()
374
+ // }
375
+ // }
369
376
370
- impl < T : Shape , OnSet , OnResize , I : SliceIndex < [ T ] > > Index < I > for SharedAttribute < T , OnSet , OnResize > {
371
- type Output = I :: Output ;
372
- #[ inline]
373
- fn index ( & self , index : I ) -> & Self :: Output {
374
- & self . data [ index]
375
- }
376
- }
377
+ // impl<T: Shape, OnSet, OnResize, I: SliceIndex<[T]>> Index<I> for SharedAttribute<T, OnSet, OnResize> {
378
+ // type Output = I::Output;
379
+ // #[inline]
380
+ // fn index(&self, index: I) -> &Self::Output {
381
+ // &self.data[index]
382
+ // }
383
+ // }
377
384
378
385
// impl<T: Shape, OnDirty> Deref for SharedAttribute<T, OnDirty> {
379
386
// type Target = Ref<Attribute<T, OnDirty>>;
@@ -420,6 +427,9 @@ impl<T: Shape, OnSet, OnResize, I: SliceIndex<[T]>> Index<I> for SharedAttribute
420
427
421
428
use enum_dispatch:: * ;
422
429
430
+ #[ derive( Debug ) ]
431
+ pub struct BadVariant ;
432
+
423
433
424
434
macro_rules! cartesian_impl {
425
435
( $out: tt [ ] $b: tt $init_b: tt, $f: ident) => {
@@ -443,17 +453,47 @@ macro_rules! cartesian {
443
453
}
444
454
445
455
macro_rules! mk_any_shape_impl {
446
- ( [ $( ( $base: ident, $param: ident) ) ,* , ] ) => {
447
- paste:: item! {
448
- #[ enum_dispatch( IsAttribute ) ]
449
- #[ derive( Derivative ) ]
450
- #[ derivative( Debug ( bound="" ) ) ]
451
- pub enum AnyAttribute <OnSet , OnResize > {
452
- $( [ <Variant $base For $param>] ( SharedAttribute <$base<$param>, OnSet , OnResize >) , ) *
453
- }
456
+ ( [ $( ( $base: ident, $param: ident) ) ,* , ] ) => { paste:: item! {
457
+ #[ enum_dispatch( IsAttribute ) ]
458
+ #[ derive( Derivative ) ]
459
+ #[ derivative( Debug ( bound="" ) ) ]
460
+ pub enum AnyAttribute <OnSet , OnResize > {
461
+ $( [ <Variant $base For $param>]
462
+ ( Attribute <$base<$param>, OnSet , OnResize >) ,
463
+ ) *
464
+ }
465
+
466
+ $( /////////////////////////////////////////////////////////////////////
467
+
468
+ impl <' t, T , S >
469
+ TryFrom <& ' t AnyAttribute <T , S >>
470
+ for & ' t Attribute <$base<$param>, T , S > {
471
+ type Error = BadVariant ;
472
+ fn try_from( v: & ' t AnyAttribute <T , S >)
473
+ -> Result <& ' t Attribute <$base<$param>, T , S >, Self :: Error > {
474
+ match v {
475
+ AnyAttribute :: [ <Variant $base For $param>] ( a) => Ok ( a) ,
476
+ _ => Err ( BadVariant )
477
+ }
478
+ }
479
+ }
480
+
481
+ impl <' t, T , S >
482
+ TryFrom <& ' t mut AnyAttribute <T , S >>
483
+ for & ' t mut Attribute <$base<$param>, T , S > {
484
+ type Error = BadVariant ;
485
+ fn try_from( v: & ' t mut AnyAttribute <T , S >)
486
+ -> Result <& ' t mut Attribute <$base<$param>, T , S >, Self :: Error > {
487
+ match v {
488
+ AnyAttribute :: [ <Variant $base For $param>] ( a) => Ok ( a) ,
489
+ _ => Err ( BadVariant )
490
+ }
491
+ }
454
492
}
493
+
494
+ ) * /////////////////////////////////////////////////////////////////////
455
495
}
456
- }
496
+ } }
457
497
458
498
macro_rules! mk_any_shape {
459
499
( $bases: tt, $params: tt) => {
@@ -462,20 +502,19 @@ macro_rules! mk_any_shape {
462
502
}
463
503
464
504
type Identity < T > = T ;
465
- mk_any_shape ! ( [ Identity , Vector2 , Vector3 , Vector4 ] , [ f32 ] ) ;
505
+ mk_any_shape ! ( [ Identity , Vector2 , Vector3 , Vector4 ] , [ f32 , i32 ] ) ;
506
+
507
+
466
508
467
509
468
510
469
511
#[ enum_dispatch]
470
512
pub trait IsAttribute < OnSet , OnResize > {
471
- fn add_element ( & self ) ;
513
+ fn add_element ( & mut self ) ;
472
514
fn len ( & self ) -> usize ;
473
515
}
474
516
475
517
476
- // impl IsShape for Vector2<f32>{}
477
- // impl IsShape for Vector3<f32>{}
478
-
479
518
480
519
481
520
0 commit comments