Skip to content

Commit

Permalink
Better errors and small clone fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikMcClure committed Nov 16, 2024
1 parent 7054b9d commit 98f72fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
9 changes: 8 additions & 1 deletion capnp-macros/src/capnp_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,14 @@ fn process_list_pattern(builder: &Ident, list_pattern: ListPattern) -> TokenStre
"Argument for capnp_build's list comprehension requires has to have 2 elements"
);
}
let (item_builder, pattern_part) = (t.elems.first().unwrap(), t.elems.last().unwrap());
let (item_builder, pattern_part) = (
t.elems
.first()
.expect(concat!("Error on ", file!(), ":", line!())),
t.elems
.last()
.expect(concat!("Error on ", file!(), ":", line!())),
);

let index_name = format_ident!("{}_listcomprehension_index", builder);
quote! {
Expand Down
15 changes: 12 additions & 3 deletions capnp-macros/src/capnproto_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ pub fn process_capnproto_rpc(namespace: TokenStream2, item: syn::ItemImpl) -> To
fn extract_generics_from_trait(
trait_: Option<(Option<syn::token::Not>, syn::Path, syn::token::For)>,
) -> syn::PathArguments {
let path: syn::Path = trait_.unwrap().1;
let path_arguments: &syn::PathArguments = &path.segments.last().unwrap().arguments;
let path: syn::Path = trait_.expect(concat!("Error on ", file!(), ":", line!())).1;
let path_arguments: &syn::PathArguments = &path
.segments
.last()
.expect(concat!("Error on ", file!(), ":", line!()))
.arguments;
if let syn::PathArguments::AngleBracketed(_) = path_arguments {
path_arguments.clone()
} else {
Expand Down Expand Up @@ -65,7 +69,12 @@ fn process_signature(
// TODO We're ignoring user's return type, might lead to confusion
let result_type = format_ident!("{}Results", type_prefix);
let result: syn::FnArg = syn::parse_quote!(mut results: #namespace::#result_type #generics); // just straight up output type
inputs.push(sig.receiver().unwrap().to_owned().into());
inputs.push(
sig.receiver()
.expect("Error: all capnproto functions must have an &self parameter!")
.to_owned()
.into(),
);
inputs.push(params);
inputs.push(result);

Expand Down
1 change: 1 addition & 0 deletions capnp/src/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ pub trait FromClientHook: crate::introspect::Introspect {

/// An untyped client.
#[cfg(feature = "alloc")]
#[derive(Clone)]
pub struct Client {
pub hook: Box<dyn ClientHook>,
}
Expand Down

0 comments on commit 98f72fa

Please sign in to comment.