Skip to content

Commit c425c49

Browse files
committed
fix: size fn as const fn
1 parent 79485fb commit c425c49

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ resolver = "2"
2222

2323
[workspace.package]
2424
authors = ["Yvictor <[email protected]>"]
25-
version = "0.1.11"
25+
version = "0.1.12"
2626
edition = "2021"
2727
license = "MIT"
2828
repository = "https://github.com/Yvictor/binary_mirror"

binary-mirror-derive/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ fn impl_binary_mirror(input: &DeriveInput) -> TokenStream {
937937
#(#methods)*
938938

939939
/// Get the size of the struct in bytes
940-
pub fn size() -> usize {
940+
pub const fn size() -> usize {
941941
std::mem::size_of::<Self>()
942942
}
943943

src/main.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use binary_mirror_derive::{BinaryMirror, BinaryEnum};
2-
use serde::{Serialize, Deserialize};
3-
use binary_mirror::{ToNative, FromNative, NativeStructCode};
4-
1+
use binary_mirror::{FromNative, NativeStructCode, ToNative};
2+
use binary_mirror_derive::{BinaryEnum, BinaryMirror};
3+
use serde::{Deserialize, Serialize};
54

65
#[derive(Debug, PartialEq, BinaryEnum, Serialize, Deserialize)]
76
enum OrderSide {
@@ -21,7 +20,7 @@ pub fn default_str() -> String {
2120

2221
#[repr(C)]
2322
#[derive(BinaryMirror)]
24-
#[bm(derive(Debug, PartialEq,Serialize, Deserialize))]
23+
#[bm(derive(Debug, PartialEq, Serialize, Deserialize))]
2524
pub struct SomePayload {
2625
#[bm(type = "str")]
2726
company: [u8; 10],
@@ -37,7 +36,14 @@ pub struct SomePayload {
3736
// date: [u8; 8],
3837
// #[bm(type = "time", format = "%H%M%S")]
3938
// time: [u8; 6],
40-
#[bm(type = "date", format = "%Y%m%d", datetime_with = "time", alias = "datetime", skip = true, default_func = "now")]
39+
#[bm(
40+
type = "date",
41+
format = "%Y%m%d",
42+
datetime_with = "time",
43+
alias = "datetime",
44+
skip = true,
45+
default_func = "now"
46+
)]
4147
date: [u8; 8],
4248
#[bm(type = "time", format = "%H%M%S", skip = true)]
4349
time: [u8; 6],
@@ -52,7 +58,7 @@ pub struct SomePayload {
5258
}
5359

5460
// #[tokio::main]
55-
// async
61+
// async
5662
fn main() {
5763
// 初始化 tracing
5864
tracing_subscriber::fmt()

0 commit comments

Comments
 (0)