Skip to content

Commit 171e02b

Browse files
authored
Update quick start example. (#130)
1 parent 47ee9e9 commit 171e02b

File tree

1 file changed

+39
-47
lines changed
  • phper-doc/doc/_02_quick_start/_02_write_a_simple_http_client

1 file changed

+39
-47
lines changed

phper-doc/doc/_02_quick_start/_02_write_a_simple_http_client/index.md

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ Before writing the code, we first prepare the dependency and startup code.
6161
1. Add the metadata to the `Cargo.toml` to build the `.so` file.
6262

6363
```toml
64-
# Cargo.toml
65-
6664
[lib]
6765
crate-type = ["cdylib"]
6866
```
@@ -92,8 +90,6 @@ Now let's begin to finish the logic.
9290
1. First, we create `src/errors.rs` to make the `HttpClientException` class:
9391

9492
```rust
95-
/*** src/errors.rs ***/
96-
9793
use phper::{
9894
classes::{ClassEntry, ClassEntity},
9995
errors::{exception_class, Throwable},
@@ -148,49 +144,45 @@ Now let's begin to finish the logic.
148144
1. Then, create the `HttpClientBuilder` class in `src/client.rs`.
149145

150146
```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+
#
194186
use phper::{
195187
alloc::ToRefOwned,
196188
classes::{StaticStateClass, Visibility},

0 commit comments

Comments
 (0)