Skip to content

Commit

Permalink
chore: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Jan 24, 2024
1 parent 5e50f4d commit 4a6ec41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ in its own `cross_staking` module (note the underscore). This is a requirement r
now - Sylvia generates all the messages and boilerplate in this module and will try
to access them through this module. If the interface's name is a camel-case
version of the last module path's segment, the `as InterfaceName` can be omitted.
F.e. `#[messages(cw1 as Cw1)]` can be reduced to `#[messages(cw1)]`


Then there is the `Error` type embedded in the trait - it is also needed there,
Expand Down
26 changes: 7 additions & 19 deletions sylvia-derive/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,34 +359,22 @@ impl Parse for ContractMessageAttr {
.map(|name| name.ident.to_string().to_case(Case::UpperCamel))
{
emit_warning!(
variant.span(),
"Interface name `as {}` can be omitted, since it's corresponds to the path's last segment.",
variant
variant.span(), "Redundant `as {}`.", variant;
note = "Interface name is a camel case version of the path and can be auto deduced."
)
}
variant
} else if let Some(module_name) = &module.segments.last() {
let interface_name = module_name.ident.to_string().to_case(Case::UpperCamel);
syn::Ident::new(&interface_name, module.span())
} else {
syn::Ident::new(
&module
.segments
.last()
.ok_or_else(|| {
let err =
"#`[message(..)]` attribute without `as TraitName` needs to provide a path";
emit_error!(module.span(), err);
syn::Error::new(module.span(), err)
})?
.ident
.to_string()
.to_case(Case::UpperCamel),
module.span()
)
Ident::new("", module.span())
};
let customs = interface_has_custom(input)?;
if !input.is_empty() {
return Err(Error::new(
input.span(),
"Unexpected token on the end of `message` attribtue",
"Unexpected token on the end of `messages` attribtue",
));
}
Ok(Self {
Expand Down

0 comments on commit 4a6ec41

Please sign in to comment.