Skip to content

Commit 1727ca4

Browse files
authored
SATS: add Impossible helper type (#2929)
1 parent ae21aae commit 1727ca4

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

crates/core/src/messages/control_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ pub struct NodeStatus {
7474
#[repr(i32)]
7575
pub enum HostType {
7676
Wasm = 0,
77-
Js,
77+
Js = 1,
7878
}

crates/sats/src/ser.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ mod impls;
66
pub mod serde;
77

88
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};
1011
use ethnum::{i256, u256};
1112
pub use spacetimedb_bindings_macro::Serialize;
1213

@@ -385,3 +386,50 @@ impl<S: SerializeSeqProduct> SerializeNamedProduct for ForwardNamedToSeqProduct<
385386
self.tup.end()
386387
}
387388
}
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

Comments
 (0)