use borsh::BorshSerialize;
use zerocopy_str::ZeroCopyStr;
#[derive(BorshSerialize)]
pub enum StrEnum<'a> {
Png,
Jpeg,
Gif,
Mp3,
Mp4,
Other(&'a str), }
pub enum ZeroCopyStrEnum<'a> {
Png,
Jpeg,
Gif,
Mp3,
Mp4,
Other(ZeroCopyStr<'a>), }
fn main() {
let png = StrEnum::Png;
let other = StrEnum::Other("pdf");
let other_inner_zc = ZeroCopyStr::from("pdf");
let png_borsh_bytes = borsh::to_vec(&png).unwrap();
let png_zc_bytes = vec![0]; let other_borsh_bytes = borsh::to_vec(&other).unwrap();
let other_zc_bytes = [[5].as_ref(), other_inner_zc.to_vec().as_ref()].concat();
println!("png: {} vs {}", png_borsh_bytes.len(), png_zc_bytes.len());
println!(
"other: {} vs {}",
other_borsh_bytes.len(),
other_zc_bytes.len()
);
}