jamesmunns / postcard

A no_std + serde compatible message library for Rust
Apache License 2.0
929 stars 88 forks source link

`#[postcard(crate = ...)]` analogous to `#[serde(crate = "...")]` #183

Open max-heller opened 6 days ago

max-heller commented 6 days ago

Analogous to #[serde(crate = "...")], it'd be great to have a #[postcard(crate = ...)] for #[derive(Schema)] to make it possible to re-export postcard derives from another crate without needing an additional direct dependency on postcard or postcard_schema.

This https://github.com/jamesmunns/postcard/blob/70111772ee231364daeac7cd11063352f19bc930/source/postcard-derive/src/schema.rs#L22-L24 would have to become something like

impl #impl_generics #postcard::Schema for #name #ty_generics #where_clause {
    const SCHEMA: &'static #postcard::schema::NamedType = #ty;
}

Parsing could likely be handled similarly to https://github.com/jamesmunns/postcard/pull/154, although it'd be nice to support #[postcard(crate = postcard)] instead of requiring a string literal like #[postcard(crate = "postcard")] (IIRC, the reason serde uses string literals is for backwards-compatibility).

jamesmunns commented 4 hours ago

I'm open to a PR for this!