I'm trying t skip some fields with rkyv but I have managed to get it working yet. Frankly I don't want to think too much about it right now so I will be temporarily using bincode. I still believe in rkyv but it may not be ready yet for my use-case. I will keep it in my backlog to reimplement ser-de in rkyv.
use bytecheck::CheckBytes;
use llvm_sys::{
target::{LLVM_InitializeNativeAsmPrinter, LLVM_InitializeNativeTarget},
LLVMModule,
};
use rkyv::{
with::{ArchiveWith, DeserializeWith, SerializeWith},
Fallible, Archive, Deserialize, Serialize
};
#[derive(Debug, Serialize, Deserialize, Archive)]
#[archive_attr(derive(CheckBytes, Debug))]
pub struct LLVM {
#[with(Skip)]
pub module: LLVMModule,
}
pub struct Skip;
impl<F> ArchiveWith<F> for Skip {
type Archived = ();
type Resolver = ();
unsafe fn resolve_with(_: &F, _: usize, _: Self::Resolver, _: *mut Self::Archived) {}
}
impl<F, S: Fallible + ?Sized> SerializeWith<F, S> for Skip {
fn serialize_with(_: &F, _: &mut S) -> Result<(), S::Error> {
Ok(())
}
}
impl<F: Skipper, D: Fallible + ?Sized> DeserializeWith<(), F, D> for Skip {
fn deserialize_with(_: &(), _: &mut D) -> Result<F, D::Error> {
Ok(F::skip())
}
}
pub trait Skipper {
fn skip() -> Self;
}
impl Skipper for LLVMModule {
fn skip() -> Self {
todo!()
// Self {}
}
}