mirror of
https://github.com/Drop-OSS/drop
synced 2026-08-27 14:23:05 -04:00
feat: add native_model_id_str and native_model_version_str
This commit is contained in:
parent
07c8900dde
commit
003d1f3b1d
4 changed files with 20 additions and 1 deletions
|
|
@ -8,6 +8,10 @@ pub(crate) fn generate_native_model_id(model_attributes: &ModelAttributes) -> To
|
|||
fn native_model_id() -> u32 {
|
||||
#native_model_id
|
||||
}
|
||||
|
||||
fn native_model_id_str() -> &'static str {
|
||||
stringify!(#native_model_id)
|
||||
}
|
||||
};
|
||||
gen
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ pub(crate) fn generate_native_model_version(model_attributes: &ModelAttributes)
|
|||
fn native_model_version() -> u32 {
|
||||
#native_model_version
|
||||
}
|
||||
|
||||
fn native_model_version_str() -> &'static str {
|
||||
stringify!(#native_model_version)
|
||||
}
|
||||
};
|
||||
gen
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ use crate::{DecodeResult, EncodeResult, Result};
|
|||
|
||||
pub trait Model: Sized {
|
||||
fn native_model_id() -> u32;
|
||||
fn native_model_id_str() -> &'static str;
|
||||
fn native_model_version() -> u32;
|
||||
fn native_model_version_str() -> &'static str;
|
||||
|
||||
// --------------- Decode ---------------
|
||||
fn native_model_decode_body(data: Vec<u8>, id: u32) -> DecodeResult<Self>
|
||||
|
|
|
|||
|
|
@ -28,10 +28,19 @@ impl From<Foo2> for Foo1 {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
fn get_id_version_int() {
|
||||
assert_eq!(Foo1::native_model_id(), 1);
|
||||
assert_eq!(Foo1::native_model_version(), 1);
|
||||
|
||||
assert_eq!(Foo2::native_model_id(), 1);
|
||||
assert_eq!(Foo2::native_model_version(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_id_version_str() {
|
||||
assert_eq!(Foo1::native_model_id_str(), "1");
|
||||
assert_eq!(Foo1::native_model_version_str(), "1");
|
||||
|
||||
assert_eq!(Foo2::native_model_id_str(), "1");
|
||||
assert_eq!(Foo2::native_model_version_str(), "2");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue