Skip to content

Commit

Permalink
chore: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Aug 8, 2024
1 parent 1e6b6c0 commit ce8050c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 52 deletions.
8 changes: 4 additions & 4 deletions examples/interfaces/generic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ mod tests {
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
RetT = SvCustomMsg,
RetT = Empty,
Error = (),
> as super::sv::InterfaceMessagesApi>::Exec::generic_exec_one(
vec![CosmosMsg::Custom(SvCustomMsg {})],
Expand All @@ -186,7 +186,7 @@ mod tests {
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
RetT = SvCustomMsg,
RetT = Empty,
Error = (),
> as super::sv::InterfaceMessagesApi>::Exec::generic_exec_two(
vec![CosmosMsg::Custom(SvCustomMsg {})],
Expand All @@ -203,7 +203,7 @@ mod tests {
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
RetT = SvCustomMsg,
RetT = Empty,
Error = (),
> as super::sv::InterfaceMessagesApi>::Sudo::generic_sudo_one(
CosmosMsg::Custom(SvCustomMsg {}),
Expand All @@ -219,7 +219,7 @@ mod tests {
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
RetT = SvCustomMsg,
RetT = Empty,
Error = (),
> as super::sv::InterfaceMessagesApi>::Sudo::generic_sudo_two(
CosmosMsg::Custom(SvCustomMsg {}),
Expand Down
4 changes: 2 additions & 2 deletions sylvia-derive/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<'a> InterfaceInput<'a> {
let Self {
associated_types,
item,
custom,
..
} = self;
let messages = self.emit_messages();
let associated_names: Vec<_> = associated_types
Expand All @@ -102,7 +102,7 @@ impl<'a> InterfaceInput<'a> {
let querier =
Querier::new(&query_variants, associated_types, &item.ident).emit_querier_trait();

let interface_messages = Api::new(item, associated_types, custom).emit();
let interface_messages = Api::new(item, associated_types).emit();

let multitest_helpers = self.emit_multitest_helpers();

Expand Down
23 changes: 2 additions & 21 deletions sylvia-derive/src/interface/communication/api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::crate_module;
use crate::parser::variant_descs::AsVariantDescs;
use crate::parser::{Custom, MsgType};
use crate::parser::MsgType;
use crate::types::associated_types::{AssociatedTypes, ItemType};
use crate::types::msg_variant::MsgVariants;
use proc_macro2::TokenStream;
Expand All @@ -9,28 +8,20 @@ use syn::ItemTrait;

pub struct Api<'a> {
source: &'a ItemTrait,
custom: &'a Custom,
associated_types: &'a AssociatedTypes<'a>,
}

impl<'a> Api<'a> {
pub fn new(
source: &'a ItemTrait,
associated_types: &'a AssociatedTypes<'a>,
custom: &'a Custom,
) -> Self {
pub fn new(source: &'a ItemTrait, associated_types: &'a AssociatedTypes<'a>) -> Self {
Self {
source,
custom,
associated_types,
}
}

pub fn emit(&self) -> TokenStream {
let sylvia = crate_module();
let Self {
source,
custom,
associated_types,
} = self;

Expand Down Expand Up @@ -58,20 +49,10 @@ impl<'a> Api<'a> {
&source.generics.where_clause,
);

let where_clause = &self.associated_types.as_where_clause();
let custom_query = custom.query_or_default();
let exec_generics = &exec_variants.used_generics();
let query_generics = &query_variants.used_generics();
let sudo_generics = &sudo_variants.used_generics();

let phantom = if !generics.is_empty() {
quote! {
_phantom: std::marker::PhantomData<( #(#generics,)* )>,
}
} else {
quote! {}
};

quote! {
pub trait InterfaceMessagesApi {
type Exec;
Expand Down
11 changes: 4 additions & 7 deletions sylvia-derive/src/interface/communication/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::parser::check_generics::GetPath;
use crate::types::associated_types::{AssociatedTypes, ItemType};
use crate::types::msg_field::MsgField;
use crate::types::msg_variant::{MsgVariant, MsgVariants};
use crate::utils::{emit_bracketed_generics, SvCasing};
use crate::utils::SvCasing;

pub struct Executor<'a, Generic> {
variants: &'a MsgVariants<'a, Generic>,
Expand Down Expand Up @@ -46,14 +46,11 @@ where
.map(ItemType::as_name)
.collect();
let all_generics: Vec<_> = associated_types.all_names().collect();
let assoc_types: Vec<_> = generics
.iter()
.map(|assoc| quote! {Self:: #assoc})
.collect();
let bracketed_generics = emit_bracketed_generics(&assoc_types);

let accessor = MsgType::Exec.as_accessor_name();
let executor_api_path = quote! { < dyn #interface_name < Error = (), #(#generics = Self:: #generics,)* > as InterfaceMessagesApi >:: #accessor };
let executor_api_path = quote! {
< dyn #interface_name < Error = (), #(#generics = Self:: #generics,)* > as InterfaceMessagesApi >:: #accessor
};

let methods_trait_impl = variants
.variants()
Expand Down
11 changes: 4 additions & 7 deletions sylvia-derive/src/interface/communication/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::parser::check_generics::GetPath;
use crate::types::associated_types::{AssociatedTypes, ItemType};
use crate::types::msg_field::MsgField;
use crate::types::msg_variant::{MsgVariant, MsgVariants};
use crate::utils::{emit_bracketed_generics, SvCasing};
use crate::utils::SvCasing;

pub struct Querier<'a, Generic> {
variants: &'a MsgVariants<'a, Generic>,
Expand Down Expand Up @@ -46,13 +46,10 @@ where
.map(ItemType::as_name)
.collect();
let all_generics: Vec<_> = associated_types.all_names().collect();
let assoc_types: Vec<_> = generics
.iter()
.map(|assoc| quote! {Self:: #assoc})
.collect();
let bracketed_generics = emit_bracketed_generics(&assoc_types);
let accessor = MsgType::Query.as_accessor_name();
let api_path = quote! { < dyn #interface_name < Error = (), #(#generics = Self:: #generics,)* > as InterfaceMessagesApi > :: #accessor };
let api_path = quote! {
< dyn #interface_name < Error = (), #(#generics = Self:: #generics,)* > as InterfaceMessagesApi > :: #accessor
};

let methods_trait_impl = variants
.variants()
Expand Down
15 changes: 4 additions & 11 deletions sylvia-derive/src/interface/mt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::parser::attributes::msg::MsgType;
use crate::parser::variant_descs::AsVariantDescs;
use crate::types::associated_types::AssociatedTypes;
use crate::types::msg_variant::{MsgVariant, MsgVariants};
use crate::utils::{emit_bracketed_generics, SvCasing};
use crate::utils::SvCasing;

pub struct MtHelpers<'a> {
source: &'a ItemTrait,
Expand Down Expand Up @@ -88,16 +88,9 @@ impl<'a> MtHelpers<'a> {
.map(|associated| &associated.ident)
.collect();

let associated_args_for_api: Vec<_> = associated_types
.without_error()
.map(|associated| {
let assoc = &associated.ident;
quote! { Self:: #assoc }
})
.collect();

let bracketed_generics = emit_bracketed_generics(&associated_args_for_api);
let api = quote! { < dyn #interface_name < Error = (), #(#associated_args = Self:: #associated_args,)* > as InterfaceMessagesApi > };
let api = quote! {
< dyn #interface_name < Error = (), #(#associated_args = Self:: #associated_args,)* > as InterfaceMessagesApi >
};

let associated_types_declaration = associated_types.without_error();

Expand Down

0 comments on commit ce8050c

Please sign in to comment.