diff --git a/Cargo.toml b/Cargo.toml index 4b77d15..e6a4fd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,5 +24,3 @@ bincode = { version = "2.0.0-rc.3", default-features = false, features = [ simple_logger = "5.0.0" rp2040-hal = "0.10.2" rp2040-pac = "0.6.0" -serde = { version = "1.0.216", features = ["derive"] } -serde_json = "1.0.133" diff --git a/builds/ground/Cargo.toml b/builds/ground/Cargo.toml index 06ffe89..39ea533 100644 --- a/builds/ground/Cargo.toml +++ b/builds/ground/Cargo.toml @@ -5,11 +5,9 @@ edition = "2021" [dependencies] rfe.path = "../../rfe" -rfe.features = ["std", "serde"] +rfe.features = ["std", "reflect"] anyhow.workspace = true simple_logger = "5.0.0" log.workspace = true -serde_json.workspace = true -serde.workspace = true egui = "0.30.0" eframe = "0.30.0" diff --git a/rfe/Cargo.toml b/rfe/Cargo.toml index 2efbc78..a9e339e 100644 --- a/rfe/Cargo.toml +++ b/rfe/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" default = [] std = ["dep:mio"] rp2040 = ["dep:rp2040-hal", "dep:rp2040-pac"] -serde = ["dep:serde"] +reflect = [] [dependencies] bincode.workspace = true @@ -18,4 +18,3 @@ mio = { version = "1.0.2", features = ["net", "os-poll"], optional = true } rp2040-hal = { workspace = true, optional = true } rp2040-pac = { workspace = true, optional = true } macros.path = "macros" -serde = { workspace = true, optional = true } diff --git a/rfe/macros/src/macros.rs b/rfe/macros/src/macros.rs index 7fdcdb2..9724487 100644 --- a/rfe/macros/src/macros.rs +++ b/rfe/macros/src/macros.rs @@ -71,7 +71,7 @@ pub fn kind_derive(input: TokenStream) -> TokenStream { let expanded = quote! { #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash, Encode, Decode)] - #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] + #[cfg_attr(feature = "reflect", derive(Reflect))] pub enum #kind_name { #[default] #(#kind_enum_arms)* @@ -103,161 +103,6 @@ pub fn kind_derive(input: TokenStream) -> TokenStream { TokenStream::from(expanded) } -#[proc_macro_derive(ToCsv)] -pub fn to_csv_derive(input: TokenStream) -> TokenStream { - let input = parse_macro_input!(input as DeriveInput); - - let name = input.ident; - let name_s = name.to_string(); - - let expanded = match input.data { - Data::Struct(data_struct) => { - let fields = data_struct.fields; - - let arms = fields.iter().map(|field| { - let field_ident = field.clone().ident.unwrap(); - let field_name = field_ident.to_string(); - - quote! { { - let mut field_csvs: alloc::vec::Vec = (&self.#field_ident as &dyn ToCsv).to_csv(); - for entry in &mut field_csvs { - *entry = format!("{}.{}", #field_name, &entry); - } - values.extend(field_csvs); - } } - }); - - let arms_enum = fields.iter().map(|field| { - let field_ident = field.clone().ident.unwrap(); - let field_name = field_ident.to_string(); - - quote! { { - let mut field_csvs: alloc::vec::Vec = (&self.#field_ident as &dyn ToCsv).enumerate(); - - for entry in &mut field_csvs { - *entry = format!("{}.{}", #field_name, &entry); - } - values.extend(field_csvs); - } } - }); - - quote! { - impl ToCsv for #name { - fn to_csv(&self) -> alloc::vec::Vec { - extern crate alloc; - use alloc::format; - - let mut values:alloc::vec::Vec = alloc::vec::Vec::new(); - #(#arms)* - return values; - } - - fn enumerate(&self) -> alloc::vec::Vec { - extern crate alloc; - use alloc::format; - let mut values:alloc::vec::Vec = alloc::vec::Vec::new(); - #(#arms_enum)* - return values; - - } - } - } - } - Data::Enum(data_enum) => { - let variants = data_enum.variants; - let arms = variants.iter().map(|variant| { - let variant_name = &variant.ident; - let variant_name_s = variant_name.to_string(); - - match &variant.fields { - Fields::Unit => { - quote! { Self::#variant_name => values.push(format!(" = {}::{}", #name_s, #variant_name_s)), } - // quote! { Self::#variant_name => {}, } - } - Fields::Unnamed(_) => { - quote! {Self::#variant_name(l) => { - let mut field_csvs: alloc::vec::Vec = (l as &dyn ToCsv).to_csv(); - for entry in &mut field_csvs { - *entry = format!("{}.{}", #variant_name_s, &entry); - } - values.extend(field_csvs); - },} - } - Fields::Named(_) => { - panic!("Named fields not supported by ToCsv"); - } - } - }); - - let arms_enum = variants.iter().map(|variant| { - let variant_name = &variant.ident; - let variant_name_s = variant_name.to_string(); - - match &variant.fields { - Fields::Unit => { - quote! { values.push(format!(" = {}::{}", #name_s, #variant_name_s)); } - } - Fields::Unnamed(var) => { - let var_type = - if let Some(first_field) = var.unnamed.first() { - first_field - } else { - panic!("Struct has no fields!"); - }; - quote! { - { - let l = #var_type::default(); - let mut field_csvs: alloc::vec::Vec = (&l as &dyn ToCsv).enumerate(); - - for entry in &mut field_csvs { - *entry = format!("{}.{}", #variant_name_s, &entry); - } - values.extend(field_csvs); - } - } - - } - Fields::Named(_) => { - panic!("Named fields not supported by ToCsv"); - } - } - }); - - quote! { - impl ToCsv for #name { - fn to_csv(&self) -> alloc::vec::Vec { - extern crate alloc; - use alloc::format; - let mut values: alloc::vec::Vec = alloc::vec::Vec::new(); - - match self { - #(#arms)* - } - return values; - } - - fn enumerate(&self) -> alloc::vec::Vec { - extern crate alloc; - use alloc::format; - - let mut values:alloc::vec::Vec = alloc::vec::Vec::new(); - #(#arms_enum)* - return values; - - } - } - } - } - Data::Union(_data_union) => { - return syn::Error::new_spanned(name, "ToCsv not implemented for unions") - .to_compile_error() - .into(); - } - }; - - TokenStream::from(expanded) -} - #[proc_macro_derive(Reflect)] pub fn reflect_derive(input: TokenStream) -> TokenStream { @@ -275,52 +120,38 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream { let field_name = field_ident.to_string(); quote! { { - fields.push((#field_name, &mut self.#field_ident as &mut dyn Reflect)); - } } - }); - - let arms_enum = fields.iter().map(|field| { - let field_ident = field.clone().ident.unwrap(); - let field_name = field_ident.to_string(); - - quote! { { - let mut field_csvs: alloc::vec::Vec = (&self.#field_ident as &dyn ToCsv).enumerate(); - - for entry in &mut field_csvs { - *entry = format!("{}.{}", #field_name, &entry); - } - values.extend(field_csvs); + fields.push((#field_name, &mut self.#field_ident as &mut dyn rfe::reflect::Reflect)); } } }); quote! { - impl Reflect for #name { - fn reflect_type(&self) -> ReflectType { - ReflectType::Structure + impl rfe::reflect::Reflect for #name { + fn reflect_type(&self) -> rfe::reflect::ReflectType { + rfe::reflect::ReflectType::Structure } fn type_name(&self) -> &str { #name_s } - fn fields(&mut self) -> Vec<(&str, &mut dyn Reflect)> { - let mut fields = Vec::new(); + fn fields(&mut self) -> alloc::vec::Vec<(&str, &mut dyn rfe::reflect::Reflect)> { + let mut fields = alloc::vec::Vec::new(); #(#field_arms)* fields } - fn set_value(&mut self, value: ReflectValue) { + fn set_value(&mut self, value: rfe::reflect::ReflectValue) { } - fn get_value(&self) -> ReflectValue { - ReflectValue::None + fn get_value(&self) -> rfe::reflect::ReflectValue { + rfe::reflect::ReflectValue::None } - fn variants(&self) -> Vec<(&str, Box)> { - Vec::new() + fn variants(&self) -> alloc::vec::Vec<(&str, alloc::boxed::Box)> { + alloc::vec::Vec::new() } - fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { + fn as_variant(&mut self, _i: usize) -> Option<&mut dyn rfe::reflect::Reflect> { None } } @@ -329,13 +160,10 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream { - - Data::Enum(data_enum) => { let variants = data_enum.variants; let as_arms = variants.iter().enumerate().map(|(i, variant)| { let variant_name = &variant.ident; - let variant_name_s = variant_name.to_string(); match &variant.fields { Fields::Unit => { @@ -345,7 +173,6 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream { return Some(self); } } - // quote! { Self::#variant_name => {}, } } Fields::Unnamed(_) => { quote! { @@ -358,7 +185,7 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream { } } Fields::Named(_) => { - panic!("Named fields not supported by ToCsv"); + panic!("Named fields not supported by Reflect"); } } }); @@ -371,7 +198,7 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream { Fields::Unit => { quote! { { - let value: Box = Box::new(Self::#variant_name); + let value: alloc::boxed::Box = alloc::boxed::Box::new(Self::#variant_name); variants.push((#variant_name_s, value)); } } @@ -379,46 +206,46 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream { Fields::Unnamed(_) => { quote! { { - let value: Box = Box::new(Self::#variant_name(Default::default())); + let value: alloc::boxed::Box = alloc::boxed::Box::new(Self::#variant_name(Default::default())); variants.push((#variant_name_s, value)); } } } Fields::Named(_) => { - panic!("Named fields not supported by ToCsv"); + panic!("Named fields not supported by Reflect"); } } }); quote! { - impl Reflect for #name { - fn reflect_type(&self) -> ReflectType { - ReflectType::Enumeration + impl rfe::reflect::Reflect for #name { + fn reflect_type(&self) -> rfe::reflect::ReflectType { + rfe::reflect::ReflectType::Enumeration } fn type_name(&self) -> &str { #name_s } - fn fields(&mut self) -> Vec<(&str, &mut dyn Reflect)> { - Vec::new() + fn fields(&mut self) -> alloc::vec::Vec<(&str, &mut dyn rfe::reflect::Reflect)> { + alloc::vec::Vec::new() } - fn set_value(&mut self, value: ReflectValue) { + fn set_value(&mut self, value: rfe::reflect::ReflectValue) { } - fn get_value(&self) -> ReflectValue { - ReflectValue::None + fn get_value(&self) -> rfe::reflect::ReflectValue { + rfe::reflect::ReflectValue::None } - fn variants(&self) -> Vec<(&str, Box)> { - let mut variants = Vec::new(); + fn variants(&self) -> alloc::vec::Vec<(&str, alloc::boxed::Box)> { + let mut variants = alloc::vec::Vec::new(); #(#variant_arms)* variants } - fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { + fn as_variant(&mut self, _i: usize) -> Option<&mut dyn rfe::reflect::Reflect> { #(#as_arms)* panic!("variant incorrect"); } @@ -426,7 +253,7 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream { } } Data::Union(_data_union) => { - return syn::Error::new_spanned(name, "ToCsv not implemented for unions") + return syn::Error::new_spanned(name, "Reflect not implemented for unions") .to_compile_error() .into(); } diff --git a/rfe/src/lib.rs b/rfe/src/lib.rs index 0183077..93e0546 100644 --- a/rfe/src/lib.rs +++ b/rfe/src/lib.rs @@ -10,6 +10,7 @@ pub mod msg; mod rfe; pub use rfe::*; +#[cfg(feature = "reflect")] pub mod reflect; pub use macros; diff --git a/rfe/src/msg/ds.rs b/rfe/src/msg/ds.rs index 87019f4..359393b 100644 --- a/rfe/src/msg/ds.rs +++ b/rfe/src/msg/ds.rs @@ -5,11 +5,12 @@ use alloc::string::String; use alloc::vec::Vec; use super::{TlmSetId, TlmSetItem}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; +use crate as rfe; +#[cfg(feature = "reflect")] +use crate::macros::Reflect; #[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct DsTlmSet { pub items: Vec, pub id: TlmSetId, @@ -18,14 +19,14 @@ pub struct DsTlmSet { } #[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct DsHk { pub perf: PerfData, pub counter: u32, } #[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct DsOutData { pub counter: u32, pub bytes_written: u32, @@ -33,7 +34,7 @@ pub struct DsOutData { } #[derive(Debug, Default, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub enum DsCmd { #[default] Noop, diff --git a/rfe/src/msg/example.rs b/rfe/src/msg/example.rs index 45ac495..af6dde5 100644 --- a/rfe/src/msg/example.rs +++ b/rfe/src/msg/example.rs @@ -1,23 +1,25 @@ extern crate alloc; +use crate as rfe; +#[cfg(feature = "reflect")] +use crate::macros::Reflect; use crate::utils::PerfData; use bincode::{Decode, Encode}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; + #[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct ExampleHk { pub perf: PerfData, pub counter: u32, } #[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct ExampleOutData { pub counter: u32, } #[derive(Debug, Default, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub enum ExampleCmd { #[default] Noop, diff --git a/rfe/src/msg/hs.rs b/rfe/src/msg/hs.rs index 403333d..0a7925c 100644 --- a/rfe/src/msg/hs.rs +++ b/rfe/src/msg/hs.rs @@ -2,12 +2,13 @@ use crate::utils::PerfData; use bincode::{Decode, Encode}; extern crate alloc; +use crate as rfe; +#[cfg(feature = "reflect")] +use crate::macros::Reflect; use alloc::vec::Vec; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; #[derive(Debug, Default, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct HsHk { pub perf: PerfData, pub counter: u32, @@ -22,13 +23,13 @@ pub struct HsHk { } #[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct HsOutData { pub counter: u32, } #[derive(Debug, Default, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub enum HsCmd { #[default] Noop, diff --git a/rfe/src/msg/mod.rs b/rfe/src/msg/mod.rs index b208946..c627edc 100644 --- a/rfe/src/msg/mod.rs +++ b/rfe/src/msg/mod.rs @@ -14,12 +14,13 @@ pub use to::*; mod ds; pub use ds::*; +use crate as rfe; +#[cfg(feature = "reflect")] +use crate::macros::Reflect; use crate::time::Timestamp; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct TargetMsg { // instance is FROM for tlm, is TO for cmds pub instance: Instance, @@ -33,7 +34,7 @@ impl TargetMsg { } #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub enum Instance { #[default] None, @@ -44,7 +45,7 @@ pub enum Instance { } #[derive(Debug, Default, Clone, PartialEq, Kind, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub enum Msg { #[default] None, @@ -67,7 +68,7 @@ pub enum Msg { } #[derive(Debug, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct MsgPacket { pub instance: Instance, pub msg: Msg, @@ -93,13 +94,13 @@ impl MsgPacket { } #[derive(Debug, Default, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct SubList { pub subs: Vec, } #[derive(Debug, Default, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct ReinitAppCmd { app_name: String, } @@ -107,7 +108,7 @@ pub struct ReinitAppCmd { pub type TlmSetId = u16; #[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct TlmSetItem { pub target: TargetMsg, pub decimation: u16, diff --git a/rfe/src/msg/to.rs b/rfe/src/msg/to.rs index 7c1b509..1de42c1 100644 --- a/rfe/src/msg/to.rs +++ b/rfe/src/msg/to.rs @@ -1,14 +1,15 @@ use crate::utils::PerfData; use bincode::{Decode, Encode}; extern crate alloc; +use crate as rfe; +#[cfg(feature = "reflect")] +use crate::macros::Reflect; use alloc::vec::Vec; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; use super::{TlmSetId, TlmSetItem}; #[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct ToTlmSet { pub items: Vec, pub id: TlmSetId, @@ -16,20 +17,20 @@ pub struct ToTlmSet { } #[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct ToHk { pub perf: PerfData, pub counter: u32, } #[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct ToOutData { pub counter: u32, } #[derive(Debug, Default, Clone, PartialEq, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub enum ToCmd { #[default] Noop, diff --git a/rfe/src/reflect.rs b/rfe/src/reflect.rs index f06d192..b5cad30 100644 --- a/rfe/src/reflect.rs +++ b/rfe/src/reflect.rs @@ -96,6 +96,8 @@ impl ReflectValue { ReflectValue::Bool(b) => *b, } } + + pub fn vec(self) -> Vec {} } pub trait Reflect: std::fmt::Debug { @@ -444,125 +446,32 @@ impl Reflect for bool { } } -// impl ToCsv for bool { -// fn to_csv(&self) -> Vec { -// vec![format!(" = {}", self)] -// } -// fn enumerate(&self) -> Vec { -// vec![format!(" = bool")] -// } -// } +impl Reflect for Vec { + fn reflect_type(&self) -> ReflectType { + ReflectType::Value + } -// impl ToCsv for Vec { -// fn to_csv(&self) -> Vec { -// self.iter() -// .enumerate() -// .map(|(i, x)| { -// x.to_csv() -// .iter() -// .map(|a| format!("[{}].{}", i, a)) -// .collect::>() -// }) -// .flatten() -// .collect() -// } -// fn enumerate(&self) -> Vec { -// T::default() -// .enumerate() -// .iter() -// .map(|x| format!("[{}].{}", std::any::type_name::(), x)) -// .collect::>() -// } -// } + fn type_name(&self) -> &str { + "vec[]" + } -// impl ToCsv for [T; N] { -// fn to_csv(&self) -> Vec { -// self.iter() -// .enumerate() -// .map(|(i, x)| { -// x.to_csv() -// .iter() -// .map(|a| format!("[{}].{}", i, a)) -// .collect::>() -// }) -// .flatten() -// .collect() -// } -// fn enumerate(&self) -> Vec { -// T::default() -// .enumerate() -// .iter() -// .map(|x| format!("[{}].{}", std::any::type_name::(), x)) -// .collect::>() -// } -// } + fn fields(&mut self) -> Vec<(&str, &mut dyn Reflect)> { + Vec::new() + } -// impl ToCsv for (T1, T2) { -// fn to_csv(&self) -> Vec { -// let mut csvs = Vec::new(); -// csvs.extend(self.0.to_csv().iter().map(|x| format!("[0].{}", x))); -// csvs.extend(self.1.to_csv().iter().map(|x| format!("[1].{}", x))); -// csvs -// } -// fn enumerate(&self) -> Vec { -// vec![format!( -// " = ({}, {})", -// std::any::type_name::(), -// std::any::type_name::() -// )] -// } -// } + fn set_value(&mut self, value: ReflectValue) { + *self = value.vec(); + } -// impl ToCsv for (T1, T2, T3) { -// fn to_csv(&self) -> Vec { -// let mut csvs = Vec::new(); -// csvs.extend(self.0.to_csv().iter().map(|x| format!("[0].{}", x))); -// csvs.extend(self.1.to_csv().iter().map(|x| format!("[1].{}", x))); -// csvs.extend(self.2.to_csv().iter().map(|x| format!("[2].{}", x))); -// csvs -// } -// fn enumerate(&self) -> Vec { -// vec![format!( -// " = ({}, {}, {})", -// std::any::type_name::(), -// std::any::type_name::(), -// std::any::type_name::() -// )] -// } -// } + fn get_value(&self) -> ReflectValue { + ReflectValue::Bool(*self) + } -// impl ToCsv for (T1, T2, T3, T4) { -// fn to_csv(&self) -> Vec { -// let mut csvs = Vec::new(); -// csvs.extend(self.0.to_csv().iter().map(|x| format!("[0].{}", x))); -// csvs.extend(self.1.to_csv().iter().map(|x| format!("[1].{}", x))); -// csvs.extend(self.2.to_csv().iter().map(|x| format!("[2].{}", x))); -// csvs.extend(self.3.to_csv().iter().map(|x| format!("[3].{}", x))); -// csvs -// } -// fn enumerate(&self) -> Vec { -// vec![format!( -// " = ({}, {}, {}, {})", -// std::any::type_name::(), -// std::any::type_name::(), -// std::any::type_name::(), -// std::any::type_name::() -// )] -// } -// } + fn variants(&self) -> Vec<(&str, Box)> { + Vec::new() + } -// impl ToCsvClean for T { -// fn to_csv_clean(&self) -> Vec { -// self.to_csv().iter().map(|x| to_csv_clean(x)).collect() -// } - -// fn enumerate_clean(&self) -> Vec { -// self.enumerate().iter().map(|x| to_csv_clean(x)).collect() -// } -// } - -// fn to_csv_clean(s: &String) -> String { -// let s = s.replace(".[", "["); -// let s = s.replace(". =", " ="); -// s -// } + fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> { + None + } +} diff --git a/rfe/src/utils.rs b/rfe/src/utils.rs index 817b0c3..ddd88ca 100644 --- a/rfe/src/utils.rs +++ b/rfe/src/utils.rs @@ -4,11 +4,12 @@ use bincode::{Decode, Encode}; extern crate alloc; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; +use crate as rfe; +#[cfg(feature = "reflect")] +use crate::macros::Reflect; #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Encode, Decode)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "reflect", derive(Reflect))] pub struct PerfData { enter_time: Timestamp, diff --git a/tools/decom/Cargo.toml b/tools/decom/Cargo.toml index 9f4bb07..fc628ba 100644 --- a/tools/decom/Cargo.toml +++ b/tools/decom/Cargo.toml @@ -11,5 +11,5 @@ path = "src/decom.rs" anyhow.workspace = true log.workspace = true simple_logger.workspace = true -rfe = { path = "../../rfe", features = [] } +rfe = { path = "../../rfe", features = ["reflect"] } bincode = { workspace = true, features = ["std"] }