commands: add ::new constructors for macro generated items
This commit is contained in:
+36
-4
@@ -231,7 +231,15 @@ macro_rules! single_item_command_request {
|
||||
($name:ident, $command_name:expr, $item_type:ty) => {
|
||||
paste::paste! {
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct [<$name Request>] ($item_type);
|
||||
pub struct [<$name Request>] (pub $item_type);
|
||||
}
|
||||
|
||||
impl paste::paste! { [<$name Request>] } {
|
||||
pub fn new(item: $item_type) -> Self {
|
||||
paste::paste! {
|
||||
crate::commands::[<$name Request>](item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::commands::CommandRequest for paste::paste! { [<$name Request>] } {
|
||||
@@ -268,7 +276,15 @@ macro_rules! single_optional_item_command_request {
|
||||
($name:ident, $command_name:expr, $item_type:ty) => {
|
||||
paste::paste! {
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct [<$name Request>] (Option<$item_type>);
|
||||
pub struct [<$name Request>] (pub Option<$item_type>);
|
||||
}
|
||||
|
||||
impl paste::paste! { [<$name Request>] } {
|
||||
pub fn new(item: Option<$item_type>) -> Self {
|
||||
paste::paste! {
|
||||
crate::commands::[<$name Request>](item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::commands::CommandRequest for paste::paste! { [<$name Request>] } {
|
||||
@@ -311,7 +327,15 @@ macro_rules! single_item_command_response {
|
||||
($name:ident, $item_name:expr, $item_type:ty) => {
|
||||
paste::paste! {
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct [<$name Response>] ( $item_type );
|
||||
pub struct [<$name Response>] (pub $item_type);
|
||||
}
|
||||
|
||||
impl paste::paste! { [<$name Response>] } {
|
||||
pub fn new(item: $item_type) -> Self {
|
||||
paste::paste! {
|
||||
crate::commands::[<$name Response>](item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::commands::CommandResponse for paste::paste! { [<$name Response>] } {
|
||||
@@ -347,7 +371,15 @@ macro_rules! multi_item_command_response {
|
||||
($name:ident, $item_name:expr, $item_type:ty) => {
|
||||
paste::paste! {
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct [<$name Response>] ( Vec<$item_type> );
|
||||
pub struct [<$name Response>] (pub Vec<$item_type>);
|
||||
}
|
||||
|
||||
impl paste::paste! { [<$name Response>] } {
|
||||
pub fn new(items: Vec<$item_type>) -> Self {
|
||||
paste::paste! {
|
||||
crate::commands::[<$name Response>](items)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::commands::CommandResponse for paste::paste! { [<$name Response>] } {
|
||||
|
||||
Reference in New Issue
Block a user