Skip to content

Commit d2f772d

Browse files
committed
refactor(napi): rename NapiEnv lifetime to 'env
1 parent 65f9a43 commit d2f772d

File tree

9 files changed

+110
-110
lines changed

9 files changed

+110
-110
lines changed

napi/src/value/any.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ use super::{NapiArray, NapiBoolean, NapiNull, NapiNumber, NapiObject,
99
NapiValueType};
1010

1111
#[derive(Clone, Copy, Debug)]
12-
pub struct NapiAny<'a> {
12+
pub struct NapiAny<'env> {
1313
value: sys::napi_value,
14-
env: &'a NapiEnv,
14+
env: &'env NapiEnv,
1515
}
1616

17-
impl<'a> NapiAny<'a> {
18-
pub fn new(env: &'a NapiEnv) -> NapiResult<Self> {
17+
impl<'env> NapiAny<'env> {
18+
pub fn new(env: &'env NapiEnv) -> NapiResult<Self> {
1919
let mut value = ptr::null_mut();
2020
env.handle_status(unsafe {
2121
sys::napi_get_undefined(env.as_sys_env(), &mut value)
@@ -24,11 +24,11 @@ impl<'a> NapiAny<'a> {
2424
Ok(Self { value, env })
2525
}
2626

27-
pub fn with_value(env: &'a NapiEnv, value: sys::napi_value) -> Self {
27+
pub fn with_value(env: &'env NapiEnv, value: sys::napi_value) -> Self {
2828
Self { env, value }
2929
}
3030

31-
pub fn as_undefined(&self) -> NapiResult<NapiUndefined<'a>> {
31+
pub fn as_undefined(&self) -> NapiResult<NapiUndefined<'env>> {
3232
match self.value_type()? {
3333
NapiValueType::Undefined => {
3434
Ok(NapiUndefined::construct(self.env(), self.as_sys_value()))
@@ -40,7 +40,7 @@ impl<'a> NapiAny<'a> {
4040
}
4141
}
4242

43-
pub fn as_null(&self) -> NapiResult<NapiNull<'a>> {
43+
pub fn as_null(&self) -> NapiResult<NapiNull<'env>> {
4444
match self.value_type()? {
4545
NapiValueType::Null => {
4646
Ok(NapiNull::construct(self.env(), self.as_sys_value()))
@@ -52,7 +52,7 @@ impl<'a> NapiAny<'a> {
5252
}
5353
}
5454

55-
pub fn as_boolean(&self) -> NapiResult<NapiBoolean<'a>> {
55+
pub fn as_boolean(&self) -> NapiResult<NapiBoolean<'env>> {
5656
match self.value_type()? {
5757
NapiValueType::Boolean => {
5858
Ok(NapiBoolean::construct(self.env(), self.as_sys_value()))
@@ -64,7 +64,7 @@ impl<'a> NapiAny<'a> {
6464
}
6565
}
6666

67-
pub fn as_number(&self) -> NapiResult<NapiNumber<'a>> {
67+
pub fn as_number(&self) -> NapiResult<NapiNumber<'env>> {
6868
match self.value_type()? {
6969
NapiValueType::Number => {
7070
Ok(NapiNumber::construct(self.env(), self.as_sys_value()))
@@ -76,7 +76,7 @@ impl<'a> NapiAny<'a> {
7676
}
7777
}
7878

79-
pub fn as_string(&self) -> NapiResult<NapiString<'a>> {
79+
pub fn as_string(&self) -> NapiResult<NapiString<'env>> {
8080
match self.value_type()? {
8181
NapiValueType::String => {
8282
Ok(NapiString::construct(self.env(), self.as_sys_value()))
@@ -88,7 +88,7 @@ impl<'a> NapiAny<'a> {
8888
}
8989
}
9090

91-
pub fn as_object(&self) -> NapiResult<NapiObject<'a>> {
91+
pub fn as_object(&self) -> NapiResult<NapiObject<'env>> {
9292
match self.value_type()? {
9393
NapiValueType::Object |
9494
NapiValueType::String |
@@ -102,7 +102,7 @@ impl<'a> NapiAny<'a> {
102102
}
103103
}
104104

105-
pub fn as_array(&self) -> NapiResult<NapiArray<'a>> {
105+
pub fn as_array(&self) -> NapiResult<NapiArray<'env>> {
106106
if self.is_array()? {
107107
Ok(NapiArray::construct(self.env(), self.as_sys_value()))
108108
} else {
@@ -114,12 +114,12 @@ impl<'a> NapiAny<'a> {
114114
}
115115
}
116116

117-
impl<'a> NapiValue<'a> for NapiAny<'a> {
117+
impl<'env> NapiValue<'env> for NapiAny<'env> {
118118
fn as_sys_value(&self) -> sys::napi_value {
119119
self.value
120120
}
121121

122-
fn env(&self) -> &'a NapiEnv {
122+
fn env(&self) -> &'env NapiEnv {
123123
self.env
124124
}
125125
}

napi/src/value/array.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use sys;
77
use super::{AsNapiObject, NapiAny, NapiValue, NapiValueInternal};
88

99
#[derive(Clone, Copy, Debug)]
10-
pub struct NapiArray<'a> {
10+
pub struct NapiArray<'env> {
1111
value: sys::napi_value,
12-
env: &'a NapiEnv,
12+
env: &'env NapiEnv,
1313
}
1414

15-
impl<'a> NapiArray<'a> {
16-
pub fn new(env: &'a NapiEnv) -> NapiResult<Self> {
15+
impl<'env> NapiArray<'env> {
16+
pub fn new(env: &'env NapiEnv) -> NapiResult<Self> {
1717
let mut value = ptr::null_mut();
1818
env.handle_status(unsafe {
1919
sys::napi_create_array(env.as_sys_env(), &mut value)
@@ -22,7 +22,7 @@ impl<'a> NapiArray<'a> {
2222
Ok(Self { value, env })
2323
}
2424

25-
pub fn with_len(env: &'a NapiEnv, len: usize) -> NapiResult<Self> {
25+
pub fn with_len(env: &'env NapiEnv, len: usize) -> NapiResult<Self> {
2626
let mut value = ptr::null_mut();
2727
env.handle_status(unsafe {
2828
sys::napi_create_array_with_length(
@@ -53,32 +53,32 @@ impl<'a> NapiArray<'a> {
5353
self.len().map(|l| l == 0)
5454
}
5555

56-
pub fn get(&self, index: u32) -> NapiResult<NapiAny<'a>> {
56+
pub fn get(&self, index: u32) -> NapiResult<NapiAny<'env>> {
5757
self.as_napi_object().get_element(index)
5858
}
5959

6060
pub fn set<T>(&self, index: u32, value: &T) -> NapiResult<()>
6161
where
62-
T: NapiValue<'a>,
62+
T: NapiValue<'env>,
6363
{
6464
self.as_napi_object().set_element(index, value)
6565
}
6666
}
6767

68-
impl<'a> NapiValue<'a> for NapiArray<'a> {
68+
impl<'env> NapiValue<'env> for NapiArray<'env> {
6969
fn as_sys_value(&self) -> sys::napi_value {
7070
self.value
7171
}
7272

73-
fn env(&self) -> &'a NapiEnv {
73+
fn env(&self) -> &'env NapiEnv {
7474
self.env
7575
}
7676
}
7777

78-
impl<'a> NapiValueInternal<'a> for NapiArray<'a> {
79-
fn construct(env: &'a NapiEnv, value: sys::napi_value) -> Self {
78+
impl<'env> NapiValueInternal<'env> for NapiArray<'env> {
79+
fn construct(env: &'env NapiEnv, value: sys::napi_value) -> Self {
8080
Self { env, value }
8181
}
8282
}
8383

84-
impl<'a> AsNapiObject<'a> for NapiArray<'a> {}
84+
impl<'env> AsNapiObject<'env> for NapiArray<'env> {}

napi/src/value/boolean.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use sys;
77
use super::{NapiValue, NapiValueInternal};
88

99
#[derive(Clone, Copy, Debug)]
10-
pub struct NapiBoolean<'a> {
10+
pub struct NapiBoolean<'env> {
1111
value: sys::napi_value,
12-
env: &'a NapiEnv,
12+
env: &'env NapiEnv,
1313
}
1414

15-
impl<'a> NapiBoolean<'a> {
16-
fn new(env: &'a NapiEnv, value: bool) -> NapiResult<Self> {
15+
impl<'env> NapiBoolean<'env> {
16+
fn new(env: &'env NapiEnv, value: bool) -> NapiResult<Self> {
1717
let mut sys_value = ptr::null_mut();
1818
env.handle_status(unsafe {
1919
sys::napi_get_boolean(env.as_sys_env(), value, &mut sys_value)
@@ -25,11 +25,11 @@ impl<'a> NapiBoolean<'a> {
2525
})
2626
}
2727

28-
pub fn truth(env: &'a NapiEnv) -> NapiResult<Self> {
28+
pub fn truth(env: &'env NapiEnv) -> NapiResult<Self> {
2929
NapiBoolean::new(env, true)
3030
}
3131

32-
pub fn lie(env: &'a NapiEnv) -> NapiResult<Self> {
32+
pub fn lie(env: &'env NapiEnv) -> NapiResult<Self> {
3333
NapiBoolean::new(env, false)
3434
}
3535

@@ -48,18 +48,18 @@ impl<'a> NapiBoolean<'a> {
4848
}
4949
}
5050

51-
impl<'a> NapiValue<'a> for NapiBoolean<'a> {
51+
impl<'env> NapiValue<'env> for NapiBoolean<'env> {
5252
fn as_sys_value(&self) -> sys::napi_value {
5353
self.value
5454
}
5555

56-
fn env(&self) -> &'a NapiEnv {
56+
fn env(&self) -> &'env NapiEnv {
5757
self.env
5858
}
5959
}
6060

61-
impl<'a> NapiValueInternal<'a> for NapiBoolean<'a> {
62-
fn construct(env: &'a NapiEnv, value: sys::napi_value) -> Self {
61+
impl<'env> NapiValueInternal<'env> for NapiBoolean<'env> {
62+
fn construct(env: &'env NapiEnv, value: sys::napi_value) -> Self {
6363
Self { env, value }
6464
}
6565
}

napi/src/value/mod.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ pub enum NapiValueType {
3535
External,
3636
}
3737

38-
pub trait NapiValue<'a> {
38+
pub trait NapiValue<'env> {
3939
fn as_sys_value(&self) -> sys::napi_value;
40-
fn env(&self) -> &'a NapiEnv;
40+
fn env(&self) -> &'env NapiEnv;
4141

42-
fn to_napi_boolean(&self) -> NapiResult<NapiBoolean<'a>> {
42+
fn to_napi_boolean(&self) -> NapiResult<NapiBoolean<'env>> {
4343
coerce(self, sys::napi_coerce_to_bool)
4444
}
4545

46-
fn to_napi_number(&self) -> NapiResult<NapiNumber<'a>> {
46+
fn to_napi_number(&self) -> NapiResult<NapiNumber<'env>> {
4747
coerce(self, sys::napi_coerce_to_number)
4848
}
4949

50-
fn to_napi_object(&self) -> NapiResult<NapiObject<'a>> {
50+
fn to_napi_object(&self) -> NapiResult<NapiObject<'env>> {
5151
coerce(self, sys::napi_coerce_to_object)
5252
}
5353

54-
fn to_napi_string(&self) -> NapiResult<NapiString<'a>> {
54+
fn to_napi_string(&self) -> NapiResult<NapiString<'env>> {
5555
coerce(self, sys::napi_coerce_to_string)
5656
}
5757

58-
fn as_napi_any(&self) -> NapiAny<'a> {
58+
fn as_napi_any(&self) -> NapiAny<'env> {
5959
NapiAny::with_value(self.env(), self.as_sys_value())
6060
}
6161

@@ -122,7 +122,7 @@ pub trait NapiValue<'a> {
122122

123123
fn strict_equals<T>(&self, other: &T) -> NapiResult<bool>
124124
where
125-
T: NapiValue<'a> + ?Sized,
125+
T: NapiValue<'env> + ?Sized,
126126
{
127127
let env = self.env();
128128
let mut result = false;
@@ -140,17 +140,17 @@ pub trait NapiValue<'a> {
140140
}
141141
}
142142

143-
pub trait AsNapiObject<'a>: NapiValue<'a> {
144-
fn as_napi_object(&self) -> NapiObject<'a> {
143+
pub trait AsNapiObject<'env>: NapiValue<'env> {
144+
fn as_napi_object(&self) -> NapiObject<'env> {
145145
NapiObject::construct(self.env(), self.as_sys_value())
146146
}
147147
}
148148

149-
trait NapiValueInternal<'a>: NapiValue<'a> {
150-
fn construct(env: &'a NapiEnv, value: sys::napi_value) -> Self;
149+
trait NapiValueInternal<'env>: NapiValue<'env> {
150+
fn construct(env: &'env NapiEnv, value: sys::napi_value) -> Self;
151151
}
152152

153-
fn coerce<'a, T, U>(
153+
fn coerce<'env, T, U>(
154154
value: &T,
155155
napi_fn: unsafe extern "C" fn(
156156
sys::napi_env,
@@ -159,8 +159,8 @@ fn coerce<'a, T, U>(
159159
) -> sys::napi_status,
160160
) -> NapiResult<U>
161161
where
162-
T: NapiValue<'a> + ?Sized,
163-
U: NapiValueInternal<'a>,
162+
T: NapiValue<'env> + ?Sized,
163+
U: NapiValueInternal<'env>,
164164
{
165165
let env = value.env();
166166
let mut coerced_value = ptr::null_mut();
@@ -172,13 +172,13 @@ where
172172
Ok(U::construct(env, coerced_value))
173173
}
174174

175-
fn check_type<'a, T>(
175+
fn check_type<'env, T>(
176176
value: &T,
177177
napi_fn: unsafe extern "C" fn(sys::napi_env, sys::napi_value, *mut bool)
178178
-> sys::napi_status,
179179
) -> NapiResult<bool>
180180
where
181-
T: NapiValue<'a> + ?Sized,
181+
T: NapiValue<'env> + ?Sized,
182182
{
183183
let env = value.env();
184184
let mut result = false;

napi/src/value/null.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use sys;
77
use super::{NapiValue, NapiValueInternal};
88

99
#[derive(Clone, Copy, Debug)]
10-
pub struct NapiNull<'a> {
10+
pub struct NapiNull<'env> {
1111
value: sys::napi_value,
12-
env: &'a NapiEnv,
12+
env: &'env NapiEnv,
1313
}
1414

15-
impl<'a> NapiNull<'a> {
16-
pub fn new(env: &'a NapiEnv) -> NapiResult<Self> {
15+
impl<'env> NapiNull<'env> {
16+
pub fn new(env: &'env NapiEnv) -> NapiResult<Self> {
1717
let mut value = ptr::null_mut();
1818
env.handle_status(
1919
unsafe { sys::napi_get_null(env.as_sys_env(), &mut value) },
@@ -23,18 +23,18 @@ impl<'a> NapiNull<'a> {
2323
}
2424
}
2525

26-
impl<'a> NapiValue<'a> for NapiNull<'a> {
26+
impl<'env> NapiValue<'env> for NapiNull<'env> {
2727
fn as_sys_value(&self) -> sys::napi_value {
2828
self.value
2929
}
3030

31-
fn env(&self) -> &'a NapiEnv {
31+
fn env(&self) -> &'env NapiEnv {
3232
self.env
3333
}
3434
}
3535

36-
impl<'a> NapiValueInternal<'a> for NapiNull<'a> {
37-
fn construct(env: &'a NapiEnv, value: sys::napi_value) -> Self {
36+
impl<'env> NapiValueInternal<'env> for NapiNull<'env> {
37+
fn construct(env: &'env NapiEnv, value: sys::napi_value) -> Self {
3838
Self { env, value }
3939
}
4040
}

0 commit comments

Comments
 (0)