mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-26 18:31:55 +00:00
clean up traits
This commit is contained in:
@@ -199,7 +199,6 @@ impl<Context, RemoteContext, RemoteHandler, Extra> HandlerTypes
|
||||
where
|
||||
RemoteHandler: HandlerTypes,
|
||||
RemoteHandler::Params: Serialize,
|
||||
RemoteHandler::InheritedParams: Serialize,
|
||||
RemoteHandler::Ok: DeserializeOwned,
|
||||
RemoteHandler::Err: From<RpcError>,
|
||||
Extra: Send + Sync + 'static,
|
||||
@@ -217,7 +216,6 @@ where
|
||||
RemoteContext: crate::Context,
|
||||
RemoteHandler: HandlerFor<RemoteContext>,
|
||||
RemoteHandler::Params: Serialize,
|
||||
RemoteHandler::InheritedParams: Serialize,
|
||||
RemoteHandler::Ok: DeserializeOwned,
|
||||
RemoteHandler::Err: From<RpcError>,
|
||||
Extra: Serialize + Send + Sync + 'static,
|
||||
@@ -260,7 +258,6 @@ where
|
||||
Context: CallRemote<RemoteContext>,
|
||||
RemoteHandler: PrintCliResult<Context>,
|
||||
RemoteHandler::Params: Serialize,
|
||||
RemoteHandler::InheritedParams: Serialize,
|
||||
RemoteHandler::Ok: DeserializeOwned,
|
||||
RemoteHandler::Err: From<RpcError>,
|
||||
Extra: Send + Sync + 'static,
|
||||
@@ -296,7 +293,6 @@ where
|
||||
Context: crate::Context,
|
||||
RemoteHandler: CliBindings<Context>,
|
||||
RemoteHandler::Params: Serialize,
|
||||
RemoteHandler::InheritedParams: Serialize,
|
||||
RemoteHandler::Ok: DeserializeOwned,
|
||||
RemoteHandler::Err: From<RpcError>,
|
||||
Extra: Send + Sync + 'static,
|
||||
|
||||
@@ -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<RpcError>,
|
||||
H::Params: Serialize + DeserializeOwned,
|
||||
H::InheritedParams: Serialize + OrEmpty<Inherited>,
|
||||
H::InheritedParams: OrEmpty<Inherited>,
|
||||
RpcError: From<H::Err>,
|
||||
Inherited: Send + Sync + 'static,
|
||||
{
|
||||
|
||||
@@ -145,7 +145,7 @@ impl<Context, Params, InheritedParams> HandlerFor<Context>
|
||||
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<Context, Params, InheritedParams> CliBindings<Context>
|
||||
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()) {
|
||||
|
||||
@@ -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],
|
||||
);
|
||||
Reference in New Issue
Block a user