@@ -61,8 +61,6 @@ Before writing the code, we first prepare the dependency and startup code.
61
61
1 . Add the metadata to the ` Cargo.toml ` to build the ` .so ` file.
62
62
63
63
``` toml
64
- # Cargo.toml
65
-
66
64
[lib ]
67
65
crate-type = [" cdylib" ]
68
66
```
@@ -92,8 +90,6 @@ Now let's begin to finish the logic.
92
90
1 . First, we create ` src/errors.rs ` to make the ` HttpClientException ` class:
93
91
94
92
``` rust
95
- /*** src/errors.rs ***/
96
-
97
93
use phper :: {
98
94
classes :: {ClassEntry , ClassEntity },
99
95
errors :: {exception_class, Throwable },
@@ -148,49 +144,45 @@ Now let's begin to finish the logic.
148
144
1 . Then, create the ` HttpClientBuilder ` class in ` src/client.rs ` .
149
145
150
146
``` rust
151
- /*** src/errors.rs ***/
152
-
153
- use phper :: {
154
- classes :: {ClassEntry , ClassEntity },
155
- errors :: {exception_class, Throwable },
156
- };
157
-
158
- /// The exception class name of extension.
159
- const EXCEPTION_CLASS_NAME : & str = " HttpClient\ \ HttpClientException" ;
160
-
161
- pub fn make_exception_class () -> ClassEntity <()> {
162
- let mut class = ClassEntity :: new (EXCEPTION_CLASS_NAME );
163
- // The `extends` is same as the PHP class `extends`.
164
- class . extends (exception_class );
165
- class
166
- }
167
-
168
- #[derive(Debug , thiserror:: Error )]
169
- pub enum HttpClientError {
170
- #[error(transparent)]
171
- Reqwest (reqwest :: Error ),
172
-
173
- #[error(" should call '{method_name}()' before call 'body()'" )]
174
- ResponseAfterRead { method_name : String },
175
-
176
- #[error(" should not call 'body()' multi time" )]
177
- ResponseHadRead ,
178
- }
179
-
180
- impl Throwable for HttpClientError {
181
- fn get_class (& self ) -> & ClassEntry {
182
- ClassEntry :: from_globals (EXCEPTION_CLASS_NAME ). unwrap_or_else (| _ | exception_class ())
183
- }
184
- }
185
-
186
- impl From <HttpClientError > for phper :: Error {
187
- fn from (e : HttpClientError ) -> Self {
188
- phper :: Error :: throw (e )
189
- }
190
- }
191
-
192
- /*** src/client.rs ***/
193
-
147
+ # use phper :: {
148
+ # classes :: {ClassEntry , ClassEntity },
149
+ # errors :: {exception_class, Throwable },
150
+ # };
151
+ #
152
+ # /// The exception class name of extension.
153
+ # const EXCEPTION_CLASS_NAME : & str = " HttpClient\ \ HttpClientException" ;
154
+ #
155
+ # pub fn make_exception_class () -> ClassEntity <()> {
156
+ # let mut class = ClassEntity :: new (EXCEPTION_CLASS_NAME );
157
+ # // The `extends` is same as the PHP class `extends`.
158
+ # class . extends (exception_class );
159
+ # class
160
+ # }
161
+ #
162
+ # #[derive(Debug , thiserror:: Error )]
163
+ # pub enum HttpClientError {
164
+ # #[error(transparent)]
165
+ # Reqwest (reqwest :: Error ),
166
+ #
167
+ # #[error(" should call '{method_name}()' before call 'body()'" )]
168
+ # ResponseAfterRead { method_name : String },
169
+ #
170
+ # #[error(" should not call 'body()' multi time" )]
171
+ # ResponseHadRead ,
172
+ # }
173
+ #
174
+ # impl Throwable for HttpClientError {
175
+ # fn get_class (& self ) -> & ClassEntry {
176
+ # ClassEntry :: from_globals (EXCEPTION_CLASS_NAME ). unwrap_or_else (| _ | exception_class ())
177
+ # }
178
+ # }
179
+ #
180
+ # impl From <HttpClientError > for phper :: Error {
181
+ # fn from (e : HttpClientError ) -> Self {
182
+ # phper :: Error :: throw (e )
183
+ # }
184
+ # }
185
+ #
194
186
use phper :: {
195
187
alloc :: ToRefOwned ,
196
188
classes :: {StaticStateClass , Visibility },
0 commit comments