feat: add with macro option

This commit is contained in:
Vincent Herlemont
2023-10-29 09:34:45 +01:00
parent dc725a3380
commit fd5bbfd964
17 changed files with 240 additions and 120 deletions
@@ -21,6 +21,8 @@ pub(crate) struct ModelAttributes {
pub(crate) id: Option<LitInt>,
pub(crate) version: Option<LitInt>,
// type
pub(crate) with: Option<Path>,
// type
pub(crate) from: Option<Path>,
// (type, try_from::Error type)
pub(crate) try_from: Option<(Path, Path)>,
@@ -32,6 +34,8 @@ impl ModelAttributes {
self.id = Some(meta.value()?.parse()?);
} else if meta.path.is_ident("version") {
self.version = Some(meta.value()?.parse()?);
} else if meta.path.is_ident("with") {
self.with = Some(meta.value()?.parse()?);
} else if meta.path.is_ident("from") {
self.from = Some(meta.value()?.parse()?);
} else if meta.path.is_ident("try_from") {
@@ -72,6 +76,7 @@ impl Parse for TupleTryFrom {
/// Attributes:
/// - `id = u32`: The unique identifier of the model.
/// - `version = u32`: The version of the model.
/// - `with` = type: Required, the serialization/deserialization library that you use. Must implement `native_model::Encode` and `native_model::Decode`.
/// - `from = type`: Optional, the previous version of the model.
/// - `type`: The previous version of the model that you use for the From implementation.
/// - `try_from = (type, error)`: Optional, the previous version of the model with error handling.
@@ -92,7 +97,7 @@ pub fn native_model(args: TokenStream, input: TokenStream) -> TokenStream {
let native_model_id_fn = generate_native_model_id(&attrs);
let native_model_version_fn = generate_native_model_version(&attrs);
let native_model_encode_body_fn = generate_native_model_encode_body();
let native_model_encode_body_fn = generate_native_model_encode_body(&attrs);
let native_model_encode_downgrade_body_fn = generate_native_model_encode_downgrade_body(&attrs);
let native_model_decode_body_fn = generate_native_model_decode_body(&attrs);
let native_model_decode_upgrade_body_fn = generate_native_model_decode_upgrade_body(&attrs);