mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-26 09:44:40 +10:00
feat: add native_model_id_str and native_model_version_str
This commit is contained in:
committed by
Vincent Herlemont
parent
07c8900dde
commit
003d1f3b1d
@@ -8,6 +8,10 @@ pub(crate) fn generate_native_model_id(model_attributes: &ModelAttributes) -> To
|
|||||||
fn native_model_id() -> u32 {
|
fn native_model_id() -> u32 {
|
||||||
#native_model_id
|
#native_model_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn native_model_id_str() -> &'static str {
|
||||||
|
stringify!(#native_model_id)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
gen
|
gen
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ pub(crate) fn generate_native_model_version(model_attributes: &ModelAttributes)
|
|||||||
fn native_model_version() -> u32 {
|
fn native_model_version() -> u32 {
|
||||||
#native_model_version
|
#native_model_version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn native_model_version_str() -> &'static str {
|
||||||
|
stringify!(#native_model_version)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
gen
|
gen
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ use crate::{DecodeResult, EncodeResult, Result};
|
|||||||
|
|
||||||
pub trait Model: Sized {
|
pub trait Model: Sized {
|
||||||
fn native_model_id() -> u32;
|
fn native_model_id() -> u32;
|
||||||
|
fn native_model_id_str() -> &'static str;
|
||||||
fn native_model_version() -> u32;
|
fn native_model_version() -> u32;
|
||||||
|
fn native_model_version_str() -> &'static str;
|
||||||
|
|
||||||
// --------------- Decode ---------------
|
// --------------- Decode ---------------
|
||||||
fn native_model_decode_body(data: Vec<u8>, id: u32) -> DecodeResult<Self>
|
fn native_model_decode_body(data: Vec<u8>, id: u32) -> DecodeResult<Self>
|
||||||
|
|||||||
@@ -28,10 +28,19 @@ impl From<Foo2> for Foo1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_simple() {
|
fn get_id_version_int() {
|
||||||
assert_eq!(Foo1::native_model_id(), 1);
|
assert_eq!(Foo1::native_model_id(), 1);
|
||||||
assert_eq!(Foo1::native_model_version(), 1);
|
assert_eq!(Foo1::native_model_version(), 1);
|
||||||
|
|
||||||
assert_eq!(Foo2::native_model_id(), 1);
|
assert_eq!(Foo2::native_model_id(), 1);
|
||||||
assert_eq!(Foo2::native_model_version(), 2);
|
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");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user