Skip to content

Commit feb64c1

Browse files
committed
fix self convention
1 parent 5d30003 commit feb64c1

8 files changed

Lines changed: 81 additions & 79 deletions

File tree

Cargo.lock

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ license = "MIT"
1515
name = "node_api"
1616
publish = true
1717
repository = "https://github.com/tangramxyz/node_api"
18-
version = "0.2.0"
18+
version = "0.3.0"
1919

2020
[lib]
2121
path = "lib.rs"
@@ -25,7 +25,7 @@ default = []
2525
serde_1 = ["serde"]
2626

2727
[dependencies]
28-
node_api_macro = { version = "0.2", path = "macro" }
29-
node_api_system = { version = "0.2", path = "sys" }
28+
node_api_macro = { version = "0.3", path = "macro" }
29+
node_api_system = { version = "0.3", path = "sys" }
3030
num = "0.4"
3131
serde = { version = "1", optional = true }

convert.rs

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ use crate::{
55
use num::{FromPrimitive, ToPrimitive};
66

77
#[allow(clippy::wrong_self_convention, clippy::upper_case_acronyms)]
8-
pub trait ToNodeAPI<'a>: 'a {
9-
fn to_node_api(self, env: Env<'a>) -> Result<Value<'a>>;
8+
pub trait IntoNodeApi<'a>: 'a {
9+
fn into_node_api(self, env: Env<'a>) -> Result<Value<'a>>;
1010
}
1111

1212
#[allow(clippy::wrong_self_convention, clippy::upper_case_acronyms)]
1313
pub trait FromNodeAPI<'a>: 'a + Sized {
1414
fn from_node_api(value: Value<'a>) -> Result<Self>;
1515
}
1616

17-
impl<'a> ToNodeAPI<'a> for () {
18-
fn to_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
17+
impl<'a> IntoNodeApi<'a> for () {
18+
fn into_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
1919
Ok(Null::new(env)?.value())
2020
}
2121
}
@@ -27,8 +27,8 @@ impl<'a> FromNodeAPI<'a> for () {
2727
}
2828
}
2929

30-
impl<'a> ToNodeAPI<'a> for bool {
31-
fn to_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
30+
impl<'a> IntoNodeApi<'a> for bool {
31+
fn into_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
3232
Ok(Boolean::new(env, self)?.value())
3333
}
3434
}
@@ -43,8 +43,8 @@ impl<'a> FromNodeAPI<'a> for bool {
4343

4444
macro_rules! impl_to_from_for_number_type {
4545
($ty:ty) => {
46-
impl<'a> ToNodeAPI<'a> for $ty {
47-
fn to_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
46+
impl<'a> IntoNodeApi<'a> for $ty {
47+
fn into_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
4848
let value =
4949
<$ty>::to_f64(&self).ok_or_else(|| Error::message("number out of bounds"))?;
5050
let number = Number::new(env, value)?;
@@ -76,8 +76,8 @@ impl_to_from_for_number_type!(i64);
7676
impl_to_from_for_number_type!(f32);
7777
impl_to_from_for_number_type!(f64);
7878

79-
impl<'a> ToNodeAPI<'a> for char {
80-
fn to_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
79+
impl<'a> IntoNodeApi<'a> for char {
80+
fn into_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
8181
Ok(String::new(env, &self.to_string())?.value())
8282
}
8383
}
@@ -88,14 +88,14 @@ impl<'a> FromNodeAPI<'a> for char {
8888
}
8989
}
9090

91-
impl<'a> ToNodeAPI<'a> for &'a str {
92-
fn to_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
91+
impl<'a> IntoNodeApi<'a> for &'a str {
92+
fn into_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
9393
Ok(String::new(env, self)?.value())
9494
}
9595
}
9696

97-
impl<'a> ToNodeAPI<'a> for std::string::String {
98-
fn to_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
97+
impl<'a> IntoNodeApi<'a> for std::string::String {
98+
fn into_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
9999
Ok(String::new(env, self.as_str())?.value())
100100
}
101101
}
@@ -106,14 +106,14 @@ impl<'a> FromNodeAPI<'a> for std::string::String {
106106
}
107107
}
108108

109-
impl<'a, T> ToNodeAPI<'a> for Option<T>
109+
impl<'a, T> IntoNodeApi<'a> for Option<T>
110110
where
111-
T: ToNodeAPI<'a>,
111+
T: IntoNodeApi<'a>,
112112
{
113-
fn to_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
113+
fn into_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
114114
match self {
115115
None => Ok(Null::new(env)?.value()),
116-
Some(value) => Ok(value.to_node_api(env)?),
116+
Some(value) => Ok(value.into_node_api(env)?),
117117
}
118118
}
119119
}
@@ -131,14 +131,14 @@ where
131131
}
132132
}
133133

134-
impl<'a, T> ToNodeAPI<'a> for Vec<T>
134+
impl<'a, T> IntoNodeApi<'a> for Vec<T>
135135
where
136-
T: ToNodeAPI<'a>,
136+
T: IntoNodeApi<'a>,
137137
{
138-
fn to_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
138+
fn into_node_api(self, env: Env<'a>) -> Result<Value<'a>> {
139139
let mut array = Array::new(env)?;
140140
for (i, value) in self.into_iter().enumerate() {
141-
array.set(i, value.to_node_api(env)?)?;
141+
array.set(i, value.into_node_api(env)?)?;
142142
}
143143
Ok(array.value())
144144
}
@@ -158,8 +158,8 @@ where
158158
}
159159
}
160160

161-
impl<'a> ToNodeAPI<'a> for Value<'a> {
162-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
161+
impl<'a> IntoNodeApi<'a> for Value<'a> {
162+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
163163
Ok(self)
164164
}
165165
}
@@ -170,8 +170,8 @@ impl<'a> FromNodeAPI<'a> for Value<'a> {
170170
}
171171
}
172172

173-
impl<'a> ToNodeAPI<'a> for Array<'a> {
174-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
173+
impl<'a> IntoNodeApi<'a> for Array<'a> {
174+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
175175
Ok(self.value())
176176
}
177177
}
@@ -182,8 +182,8 @@ impl<'a> FromNodeAPI<'a> for Array<'a> {
182182
}
183183
}
184184

185-
impl<'a> ToNodeAPI<'a> for ArrayBuffer<'a> {
186-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
185+
impl<'a> IntoNodeApi<'a> for ArrayBuffer<'a> {
186+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
187187
Ok(self.value())
188188
}
189189
}
@@ -194,8 +194,8 @@ impl<'a> FromNodeAPI<'a> for ArrayBuffer<'a> {
194194
}
195195
}
196196

197-
impl<'a> ToNodeAPI<'a> for BigInt<'a> {
198-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
197+
impl<'a> IntoNodeApi<'a> for BigInt<'a> {
198+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
199199
Ok(self.value())
200200
}
201201
}
@@ -206,8 +206,8 @@ impl<'a> FromNodeAPI<'a> for BigInt<'a> {
206206
}
207207
}
208208

209-
impl<'a> ToNodeAPI<'a> for Boolean<'a> {
210-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
209+
impl<'a> IntoNodeApi<'a> for Boolean<'a> {
210+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
211211
Ok(self.value())
212212
}
213213
}
@@ -218,8 +218,8 @@ impl<'a> FromNodeAPI<'a> for Boolean<'a> {
218218
}
219219
}
220220

221-
impl<'a> ToNodeAPI<'a> for Buffer<'a> {
222-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
221+
impl<'a> IntoNodeApi<'a> for Buffer<'a> {
222+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
223223
Ok(self.value())
224224
}
225225
}
@@ -230,8 +230,8 @@ impl<'a> FromNodeAPI<'a> for Buffer<'a> {
230230
}
231231
}
232232

233-
impl<'a> ToNodeAPI<'a> for DataView<'a> {
234-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
233+
impl<'a> IntoNodeApi<'a> for DataView<'a> {
234+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
235235
Ok(self.value())
236236
}
237237
}
@@ -242,8 +242,8 @@ impl<'a, 'b: 'a> FromNodeAPI<'a> for DataView<'a> {
242242
}
243243
}
244244

245-
impl<'a> ToNodeAPI<'a> for Date<'a> {
246-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
245+
impl<'a> IntoNodeApi<'a> for Date<'a> {
246+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
247247
Ok(self.value())
248248
}
249249
}
@@ -254,8 +254,8 @@ impl<'a> FromNodeAPI<'a> for Date<'a> {
254254
}
255255
}
256256

257-
impl<'a, T: 'a> ToNodeAPI<'a> for External<'a, T> {
258-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
257+
impl<'a, T: 'a> IntoNodeApi<'a> for External<'a, T> {
258+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
259259
Ok(self.value())
260260
}
261261
}
@@ -266,8 +266,8 @@ impl<'a, T: 'a> FromNodeAPI<'a> for External<'a, T> {
266266
}
267267
}
268268

269-
impl<'a> ToNodeAPI<'a> for Function<'a> {
270-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
269+
impl<'a> IntoNodeApi<'a> for Function<'a> {
270+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
271271
Ok(self.value())
272272
}
273273
}
@@ -278,8 +278,8 @@ impl<'a> FromNodeAPI<'a> for Function<'a> {
278278
}
279279
}
280280

281-
impl<'a> ToNodeAPI<'a> for Null<'a> {
282-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
281+
impl<'a> IntoNodeApi<'a> for Null<'a> {
282+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
283283
Ok(self.value())
284284
}
285285
}
@@ -290,8 +290,8 @@ impl<'a> FromNodeAPI<'a> for Null<'a> {
290290
}
291291
}
292292

293-
impl<'a> ToNodeAPI<'a> for Number<'a> {
294-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
293+
impl<'a> IntoNodeApi<'a> for Number<'a> {
294+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
295295
Ok(self.value())
296296
}
297297
}
@@ -302,8 +302,8 @@ impl<'a> FromNodeAPI<'a> for Number<'a> {
302302
}
303303
}
304304

305-
impl<'a> ToNodeAPI<'a> for Object<'a> {
306-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
305+
impl<'a> IntoNodeApi<'a> for Object<'a> {
306+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
307307
Ok(self.value())
308308
}
309309
}
@@ -314,8 +314,8 @@ impl<'a> FromNodeAPI<'a> for Object<'a> {
314314
}
315315
}
316316

317-
impl<'a> ToNodeAPI<'a> for String<'a> {
318-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
317+
impl<'a> IntoNodeApi<'a> for String<'a> {
318+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
319319
Ok(self.value())
320320
}
321321
}
@@ -327,8 +327,8 @@ impl<'a> FromNodeAPI<'a> for String<'a> {
327327
}
328328
}
329329

330-
impl<'a> ToNodeAPI<'a> for Symbol<'a> {
331-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
330+
impl<'a> IntoNodeApi<'a> for Symbol<'a> {
331+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
332332
Ok(self.value())
333333
}
334334
}
@@ -339,8 +339,8 @@ impl<'a> FromNodeAPI<'a> for Symbol<'a> {
339339
}
340340
}
341341

342-
impl<'a> ToNodeAPI<'a> for TypedArray<'a> {
343-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
342+
impl<'a> IntoNodeApi<'a> for TypedArray<'a> {
343+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
344344
Ok(self.value())
345345
}
346346
}
@@ -351,8 +351,8 @@ impl<'a> FromNodeAPI<'a> for TypedArray<'a> {
351351
}
352352
}
353353

354-
impl<'a> ToNodeAPI<'a> for Undefined<'a> {
355-
fn to_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
354+
impl<'a> IntoNodeApi<'a> for Undefined<'a> {
355+
fn into_node_api(self, _env: Env<'a>) -> Result<Value<'a>> {
356356
Ok(self.value())
357357
}
358358
}

lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod serde;
88
mod value;
99

1010
pub use self::{
11-
convert::{FromNodeAPI, ToNodeAPI},
11+
convert::{FromNodeAPI, IntoNodeApi},
1212
env::Env,
1313
error::{Error, Result},
1414
value::{

macro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "MIT"
88
name = "node_api_macro"
99
publish = true
1010
repository = "https://github.com/tangramxyz/node_api"
11-
version = "0.2.0"
11+
version = "0.3.0"
1212

1313
[lib]
1414
path = "lib.rs"

macro/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn function_impl(input: proc_macro2::TokenStream) -> syn::Result<proc_macro2::To
113113
}
114114
#(#from_node_api_statements)*
115115
let output = function_impl(env, #(#args),*).map_err(|error| node_api::Error::message(error.to_string()))?;
116-
let output = node_api::ToNodeAPI::to_node_api(output, env)?;
116+
let output = node_api::IntoNodeApi::into_node_api(output, env)?;
117117
Ok(output)
118118
});
119119
let result = match result {

0 commit comments

Comments
 (0)