6
6
7
7
use crate :: ffi:: zend_string;
8
8
9
- use std:: { convert :: TryFrom , ops:: Deref , slice:: from_raw_parts} ;
9
+ use std:: { ops:: Deref , slice:: from_raw_parts} ;
10
10
11
- use crate :: {
12
- convert:: FromZval ,
13
- error:: { Error , Result } ,
14
- flags:: DataType ,
15
- types:: Zval ,
16
- } ;
11
+ use crate :: { convert:: FromZval , flags:: DataType , types:: Zval } ;
17
12
18
- /// Acts as a wrapper around [ `&[T]`] where `T` implements [`PackSlice`].
13
+ /// Acts as a wrapper around `&[T]` where `T` implements [`PackSlice`].
19
14
/// Primarily used for passing read-only binary data into Rust functions.
20
15
#[ derive( Debug ) ]
21
16
pub struct BinarySlice < ' a , T > ( & ' a [ T ] )
@@ -47,28 +42,17 @@ where
47
42
}
48
43
}
49
44
50
- impl < T > FromZval < ' _ > for BinarySlice < ' _ , T >
45
+ impl < ' a , T > FromZval < ' a > for BinarySlice < ' a , T >
51
46
where
52
47
T : PackSlice ,
53
48
{
54
49
const TYPE : DataType = DataType :: String ;
55
50
56
- fn from_zval ( zval : & Zval ) -> Option < Self > {
51
+ fn from_zval ( zval : & ' a Zval ) -> Option < Self > {
57
52
zval. binary_slice ( ) . map ( BinarySlice )
58
53
}
59
54
}
60
55
61
- impl < T > TryFrom < Zval > for BinarySlice < ' _ , T >
62
- where
63
- T : PackSlice ,
64
- {
65
- type Error = Error ;
66
-
67
- fn try_from ( value : Zval ) -> Result < Self > {
68
- Self :: from_zval ( & value) . ok_or_else ( || Error :: ZvalConversion ( value. get_type ( ) ) )
69
- }
70
- }
71
-
72
56
impl < ' a , T > From < BinarySlice < ' a , T > > for & ' a [ T ]
73
57
where
74
58
T : PackSlice ,
@@ -117,7 +101,7 @@ pub unsafe trait PackSlice: Clone {
117
101
/// * `s` - The Zend string containing the binary data.
118
102
///
119
103
/// [`pack`]: https://www.php.net/manual/en/function.pack.php
120
- fn unpack_into < ' a > ( s : & zend_string ) -> & ' a [ Self ] ;
104
+ fn unpack_into ( s : & zend_string ) -> & [ Self ] ;
121
105
}
122
106
123
107
/// Implements the [`PackSlice`] trait for a given type.
@@ -128,7 +112,7 @@ macro_rules! pack_slice_impl {
128
112
129
113
( $t: ty, $d: expr) => {
130
114
unsafe impl PackSlice for $t {
131
- fn unpack_into< ' a> ( s: & zend_string) -> & ' a [ Self ] {
115
+ fn unpack_into( s: & zend_string) -> & [ Self ] {
132
116
let bytes = ( $d / 8 ) as usize ;
133
117
let len = ( s. len as usize ) / bytes;
134
118
let ptr = s. val. as_ptr( ) as * const $t;
0 commit comments