//! sea-orm types don't always serialize how we want. this helps that, though it won't help every case. use ethers::prelude::Address; use sea_orm::prelude::Uuid; use serde::{Serialize, Serializer}; use std::convert::TryInto; use ulid::Ulid; pub fn to_fixed_length(v: Vec) -> [T; N] { v.try_into() .unwrap_or_else(|v: Vec| panic!("Expected a Vec of length {} but it was {}", N, v.len())) } pub fn vec_as_address(x: &[u8], s: S) -> Result where S: Serializer, { let x = Address::from_slice(x); x.serialize(s) } pub fn uuid_as_ulid(x: &Uuid, s: S) -> Result where S: Serializer, { let x = Ulid::from(x.as_u128()); // TODO: to_string shouldn't be needed, but i'm still seeing Uuid length x.to_string().serialize(s) }