From df388073a6bc6984e5a1236f1b20f0c057230023 Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Tue, 19 Nov 2024 13:09:01 -0700 Subject: [PATCH] clean up traits --- src/cli.rs | 4 --- src/handler/adapters.rs | 8 ++--- src/handler/parent.rs | 4 +-- src/metadata.rs | 68 ----------------------------------------- 4 files changed, 5 insertions(+), 79 deletions(-) delete mode 100644 src/metadata.rs diff --git a/src/cli.rs b/src/cli.rs index ef9f268..5890bff 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -199,7 +199,6 @@ impl HandlerTypes where RemoteHandler: HandlerTypes, RemoteHandler::Params: Serialize, - RemoteHandler::InheritedParams: Serialize, RemoteHandler::Ok: DeserializeOwned, RemoteHandler::Err: From, Extra: Send + Sync + 'static, @@ -217,7 +216,6 @@ where RemoteContext: crate::Context, RemoteHandler: HandlerFor, RemoteHandler::Params: Serialize, - RemoteHandler::InheritedParams: Serialize, RemoteHandler::Ok: DeserializeOwned, RemoteHandler::Err: From, Extra: Serialize + Send + Sync + 'static, @@ -260,7 +258,6 @@ where Context: CallRemote, RemoteHandler: PrintCliResult, RemoteHandler::Params: Serialize, - RemoteHandler::InheritedParams: Serialize, RemoteHandler::Ok: DeserializeOwned, RemoteHandler::Err: From, Extra: Send + Sync + 'static, @@ -296,7 +293,6 @@ where Context: crate::Context, RemoteHandler: CliBindings, RemoteHandler::Params: Serialize, - RemoteHandler::InheritedParams: Serialize, RemoteHandler::Ok: DeserializeOwned, RemoteHandler::Err: From, Extra: Send + Sync + 'static, diff --git a/src/handler/adapters.rs b/src/handler/adapters.rs index a54e7e9..007a8fe 100644 --- a/src/handler/adapters.rs +++ b/src/handler/adapters.rs @@ -2,10 +2,8 @@ use std::any::TypeId; use std::collections::VecDeque; use std::fmt::Debug; -use clap::{ - builder::{IntoResettable, StyledStr}, - CommandFactory, FromArgMatches, -}; +use clap::builder::{IntoResettable, StyledStr}; +use clap::{CommandFactory, FromArgMatches}; use imbl_value::imbl::OrdMap; use imbl_value::Value; use serde::de::DeserializeOwned; @@ -615,7 +613,7 @@ where H::Ok: Serialize + DeserializeOwned, H::Err: From, H::Params: Serialize + DeserializeOwned, - H::InheritedParams: Serialize + OrEmpty, + H::InheritedParams: OrEmpty, RpcError: From, Inherited: Send + Sync + 'static, { diff --git a/src/handler/parent.rs b/src/handler/parent.rs index 6238d85..9dc7e12 100644 --- a/src/handler/parent.rs +++ b/src/handler/parent.rs @@ -145,7 +145,7 @@ impl HandlerFor where Context: crate::Context, Params: Send + Sync + 'static, - InheritedParams: Serialize + Send + Sync + 'static, + InheritedParams: Send + Sync + 'static, { fn handle_sync( &self, @@ -278,7 +278,7 @@ impl CliBindings where Context: crate::Context, Params: FromArgMatches + CommandFactory + Serialize + Send + Sync + 'static, - InheritedParams: Serialize + Send + Sync + 'static, + InheritedParams: Send + Sync + 'static, { fn cli_command(&self) -> Command { let mut base = if let Some(cli) = &self.subcommands.0.as_ref().and_then(|h| h.cli()) { diff --git a/src/metadata.rs b/src/metadata.rs deleted file mode 100644 index c300f76..0000000 --- a/src/metadata.rs +++ /dev/null @@ -1,68 +0,0 @@ -macro_rules! getter_for { - ($($name:ident => $t:ty,)*) => { - $( - #[allow(unused_variables)] - fn $name(&self, command: &str, key: &str) -> Option<$t> { - None - } - )* - }; -} - -pub trait Metadata: Copy + Default + Send + Sync + 'static { - fn get(&self, command: &str, key: &str) -> Option { - Ty::from_metadata(self, command, key) - } - getter_for!( - get_bool => bool, - get_u8 => u8, - get_u16 => u16, - get_u32 => u32, - get_u64 => u64, - get_usize => usize, - get_i8 => i8, - get_i16 => i16, - get_i32 => i32, - get_i64 => i64, - get_isize => isize, - get_f32 => f32, - get_f64 => f64, - get_char => char, - get_str => &'static str, - get_bstr => &'static [u8], - ); -} - -macro_rules! impl_primitive_for { - ($($name:ident => $t:ty,)*) => { - $( - impl Primitive for $t { - fn from_metadata(m: &M, command: &str, key: &str) -> Option { - m.$name(command, key) - } - } - )* - }; -} - -pub trait Primitive: Copy { - fn from_metadata(m: &M, command: &str, key: &str) -> Option; -} -impl_primitive_for!( - get_bool => bool, - get_u8 => u8, - get_u16 => u16, - get_u32 => u32, - get_u64 => u64, - get_usize => usize, - get_i8 => i8, - get_i16 => i16, - get_i32 => i32, - get_i64 => i64, - get_isize => isize, - get_f32 => f32, - get_f64 => f64, - get_char => char, - get_str => &'static str, - get_bstr => &'static [u8], -);