clean up traits

This commit is contained in:
Aiden McClelland
2024-11-19 13:09:01 -07:00
parent 021379f21c
commit df388073a6
4 changed files with 5 additions and 79 deletions

View File

@@ -199,7 +199,6 @@ impl<Context, RemoteContext, RemoteHandler, Extra> HandlerTypes
where where
RemoteHandler: HandlerTypes, RemoteHandler: HandlerTypes,
RemoteHandler::Params: Serialize, RemoteHandler::Params: Serialize,
RemoteHandler::InheritedParams: Serialize,
RemoteHandler::Ok: DeserializeOwned, RemoteHandler::Ok: DeserializeOwned,
RemoteHandler::Err: From<RpcError>, RemoteHandler::Err: From<RpcError>,
Extra: Send + Sync + 'static, Extra: Send + Sync + 'static,
@@ -217,7 +216,6 @@ where
RemoteContext: crate::Context, RemoteContext: crate::Context,
RemoteHandler: HandlerFor<RemoteContext>, RemoteHandler: HandlerFor<RemoteContext>,
RemoteHandler::Params: Serialize, RemoteHandler::Params: Serialize,
RemoteHandler::InheritedParams: Serialize,
RemoteHandler::Ok: DeserializeOwned, RemoteHandler::Ok: DeserializeOwned,
RemoteHandler::Err: From<RpcError>, RemoteHandler::Err: From<RpcError>,
Extra: Serialize + Send + Sync + 'static, Extra: Serialize + Send + Sync + 'static,
@@ -260,7 +258,6 @@ where
Context: CallRemote<RemoteContext>, Context: CallRemote<RemoteContext>,
RemoteHandler: PrintCliResult<Context>, RemoteHandler: PrintCliResult<Context>,
RemoteHandler::Params: Serialize, RemoteHandler::Params: Serialize,
RemoteHandler::InheritedParams: Serialize,
RemoteHandler::Ok: DeserializeOwned, RemoteHandler::Ok: DeserializeOwned,
RemoteHandler::Err: From<RpcError>, RemoteHandler::Err: From<RpcError>,
Extra: Send + Sync + 'static, Extra: Send + Sync + 'static,
@@ -296,7 +293,6 @@ where
Context: crate::Context, Context: crate::Context,
RemoteHandler: CliBindings<Context>, RemoteHandler: CliBindings<Context>,
RemoteHandler::Params: Serialize, RemoteHandler::Params: Serialize,
RemoteHandler::InheritedParams: Serialize,
RemoteHandler::Ok: DeserializeOwned, RemoteHandler::Ok: DeserializeOwned,
RemoteHandler::Err: From<RpcError>, RemoteHandler::Err: From<RpcError>,
Extra: Send + Sync + 'static, Extra: Send + Sync + 'static,

View File

@@ -2,10 +2,8 @@ use std::any::TypeId;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::fmt::Debug; use std::fmt::Debug;
use clap::{ use clap::builder::{IntoResettable, StyledStr};
builder::{IntoResettable, StyledStr}, use clap::{CommandFactory, FromArgMatches};
CommandFactory, FromArgMatches,
};
use imbl_value::imbl::OrdMap; use imbl_value::imbl::OrdMap;
use imbl_value::Value; use imbl_value::Value;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
@@ -615,7 +613,7 @@ where
H::Ok: Serialize + DeserializeOwned, H::Ok: Serialize + DeserializeOwned,
H::Err: From<RpcError>, H::Err: From<RpcError>,
H::Params: Serialize + DeserializeOwned, H::Params: Serialize + DeserializeOwned,
H::InheritedParams: Serialize + OrEmpty<Inherited>, H::InheritedParams: OrEmpty<Inherited>,
RpcError: From<H::Err>, RpcError: From<H::Err>,
Inherited: Send + Sync + 'static, Inherited: Send + Sync + 'static,
{ {

View File

@@ -145,7 +145,7 @@ impl<Context, Params, InheritedParams> HandlerFor<Context>
where where
Context: crate::Context, Context: crate::Context,
Params: Send + Sync + 'static, Params: Send + Sync + 'static,
InheritedParams: Serialize + Send + Sync + 'static, InheritedParams: Send + Sync + 'static,
{ {
fn handle_sync( fn handle_sync(
&self, &self,
@@ -278,7 +278,7 @@ impl<Context, Params, InheritedParams> CliBindings<Context>
where where
Context: crate::Context, Context: crate::Context,
Params: FromArgMatches + CommandFactory + Serialize + Send + Sync + 'static, Params: FromArgMatches + CommandFactory + Serialize + Send + Sync + 'static,
InheritedParams: Serialize + Send + Sync + 'static, InheritedParams: Send + Sync + 'static,
{ {
fn cli_command(&self) -> Command { fn cli_command(&self) -> Command {
let mut base = if let Some(cli) = &self.subcommands.0.as_ref().and_then(|h| h.cli()) { let mut base = if let Some(cli) = &self.subcommands.0.as_ref().and_then(|h| h.cli()) {

View File

@@ -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<Ty: Primitive>(&self, command: &str, key: &str) -> Option<Ty> {
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: Metadata + ?Sized>(m: &M, command: &str, key: &str) -> Option<Self> {
m.$name(command, key)
}
}
)*
};
}
pub trait Primitive: Copy {
fn from_metadata<M: Metadata + ?Sized>(m: &M, command: &str, key: &str) -> Option<Self>;
}
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],
);