@@ -6,7 +6,8 @@ mod impls;
6
6
pub mod serde;
7
7
8
8
use crate :: { algebraic_value:: ser:: ValueSerializer , bsatn, buffer:: BufWriter , AlgebraicType } ;
9
- use core:: fmt;
9
+ use core:: marker:: PhantomData ;
10
+ use core:: { convert:: Infallible , fmt} ;
10
11
use ethnum:: { i256, u256} ;
11
12
pub use spacetimedb_bindings_macro:: Serialize ;
12
13
@@ -385,3 +386,50 @@ impl<S: SerializeSeqProduct> SerializeNamedProduct for ForwardNamedToSeqProduct<
385
386
self . tup . end ( )
386
387
}
387
388
}
389
+
390
+ /// A type usable in one of the associated types of [`Serializer`]
391
+ /// when the data format does not support the data.
392
+ pub struct Impossible < Ok , Error > {
393
+ // They gave each other a pledge. Unheard of, absurd.
394
+ absurd : Infallible ,
395
+ marker : PhantomData < ( Ok , Error ) > ,
396
+ }
397
+
398
+ impl < Ok , Error : self :: Error > SerializeArray for Impossible < Ok , Error > {
399
+ type Ok = Ok ;
400
+ type Error = Error ;
401
+
402
+ fn serialize_element < T : Serialize + ?Sized > ( & mut self , _: & T ) -> Result < ( ) , Self :: Error > {
403
+ match self . absurd { }
404
+ }
405
+
406
+ fn end ( self ) -> Result < Self :: Ok , Self :: Error > {
407
+ match self . absurd { }
408
+ }
409
+ }
410
+
411
+ impl < Ok , Error : self :: Error > SerializeSeqProduct for Impossible < Ok , Error > {
412
+ type Ok = Ok ;
413
+ type Error = Error ;
414
+
415
+ fn serialize_element < T : Serialize + ?Sized > ( & mut self , _: & T ) -> Result < ( ) , Self :: Error > {
416
+ match self . absurd { }
417
+ }
418
+
419
+ fn end ( self ) -> Result < Self :: Ok , Self :: Error > {
420
+ match self . absurd { }
421
+ }
422
+ }
423
+
424
+ impl < Ok , Error : self :: Error > SerializeNamedProduct for Impossible < Ok , Error > {
425
+ type Ok = Ok ;
426
+ type Error = Error ;
427
+
428
+ fn serialize_element < T : Serialize + ?Sized > ( & mut self , _: Option < & str > , _: & T ) -> Result < ( ) , Self :: Error > {
429
+ match self . absurd { }
430
+ }
431
+
432
+ fn end ( self ) -> Result < Self :: Ok , Self :: Error > {
433
+ match self . absurd { }
434
+ }
435
+ }
0 commit comments