Merge pull request #951 from napi-rs/multi-impl-gen
fix(napi-derive): codegen bug when multi impl on same file
This commit is contained in:
commit
a695c9724f
4 changed files with 19 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
|
||||
use proc_macro2::{Ident, Literal, Span, TokenStream};
|
||||
use quote::ToTokens;
|
||||
|
@ -8,6 +9,8 @@ use crate::{
|
|||
BindgenResult, FnKind, NapiImpl, NapiStruct, NapiStructKind, TryToTokens,
|
||||
};
|
||||
|
||||
static NAPI_IMPL_ID: AtomicU32 = AtomicU32::new(0);
|
||||
|
||||
// Generate trait implementations for given Struct.
|
||||
fn gen_napi_value_map_impl(name: &Ident, to_napi_val_impl: TokenStream) -> TokenStream {
|
||||
let name_str = name.to_string();
|
||||
|
@ -476,7 +479,11 @@ impl NapiImpl {
|
|||
let name_str = self.name.to_string();
|
||||
let js_name = format!("{}\0", self.js_name);
|
||||
let mod_name = Ident::new(
|
||||
&format!("__napi_impl_helper__{}", name_str),
|
||||
&format!(
|
||||
"__napi_impl_helper__{}__{}",
|
||||
name_str,
|
||||
NAPI_IMPL_ID.fetch_add(1, Ordering::SeqCst)
|
||||
),
|
||||
Span::call_site(),
|
||||
);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[napi]
|
||||
fn get_words() -> Vec<&'static str> {
|
||||
pub fn get_words() -> Vec<&'static str> {
|
||||
vec!["foo", "bar"]
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use napi::Result;
|
||||
use napi::{bindgen_prelude::Buffer, Result};
|
||||
|
||||
use crate::r#enum::Kind;
|
||||
|
||||
|
@ -75,6 +75,14 @@ impl Blake2bHasher {
|
|||
}
|
||||
}
|
||||
|
||||
#[napi]
|
||||
impl Blake2bHasher {
|
||||
#[napi]
|
||||
pub fn update(&mut self, data: Buffer) {
|
||||
self.0 += data.len() as u32;
|
||||
}
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub struct Blake2bKey(u32);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ fn get_buffer() -> Buffer {
|
|||
#[napi]
|
||||
fn append_buffer(buf: Buffer) -> Buffer {
|
||||
let mut buf = Vec::<u8>::from(buf);
|
||||
buf.push('!' as u8);
|
||||
buf.push(b'!' as u8);
|
||||
buf.into()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue