Skip to content

Commit

Permalink
chore: only hide from export, not entire declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
ozwaldorf committed Aug 28, 2022
1 parent ec42802 commit afa5eb5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
19 changes: 9 additions & 10 deletions ic-kit-macros/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,15 @@ pub fn gen_entry_point_code(
};

// only declare candid if hide is false
if !attrs.hidden.unwrap_or(false) {
declare(
entry_point,
name.clone(),
candid_name,
can_args,
can_types,
&signature.output,
)?;
}
declare(
entry_point,
name.clone(),
candid_name,
attrs.hidden.unwrap_or(false),
can_args,
can_types,
&signature.output,
)?;

Ok(quote! {
#[doc(hidden)]
Expand Down
24 changes: 16 additions & 8 deletions ic-kit-macros/src/export_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::Mutex;
use syn::{DeriveInput, Error};

struct Method {
hidden: bool,
mode: EntryPoint,
rust_name: String,
_arg_names: Vec<String>,
Expand All @@ -23,6 +24,7 @@ pub(crate) fn declare(
entry_point: EntryPoint,
rust_name: Ident,
name: String,
hidden: bool,
can_args: Vec<Ident>,
can_types: Vec<syn::Type>,
rt: &syn::ReturnType,
Expand All @@ -41,6 +43,7 @@ pub(crate) fn declare(
};

let method = Method {
hidden,
mode: entry_point,
rust_name: rust_name.to_string(),
_arg_names: can_args.iter().map(|i| i.to_string()).collect(),
Expand Down Expand Up @@ -113,6 +116,7 @@ pub fn export_service(input: DeriveInput, save_candid_path: Option<syn::LitStr>)
arg_types,
rets,
mode,
hidden,
..
},
)| {
Expand All @@ -134,15 +138,19 @@ pub fn export_service(input: DeriveInput, save_candid_path: Option<syn::LitStr>)
_ => unreachable!(),
};

quote! {
{
let mut args = Vec::new();
#(#args)*
let mut rets = Vec::new();
#(#rets)*
let func = Function { args, rets, modes: #modes };
service.push((#name.to_string(), Type::Func(func)));
if !hidden {
quote! {
{
let mut args = Vec::new();
#(#args)*
let mut rets = Vec::new();
#(#rets)*
let func = Function { args, rets, modes: #modes };
service.push((#name.to_string(), Type::Func(func)));
}
}
} else {
quote! {}
}
},
);
Expand Down

0 comments on commit afa5eb5

Please sign in to comment.