Skip to content

Commit a77e4ab

Browse files
author
yggverse
committed
add usage example
1 parent d313f90 commit a77e4ab

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,45 @@ cargo add ggemini
1818

1919
* [Documentation](https://docs.rs/ggemini/latest/ggemini/)
2020

21+
### Example
22+
23+
``` rust
24+
use gtk::gio::*;
25+
use gtk::glib::*;
26+
27+
use ggemini::client::{
28+
connection::{
29+
response::meta::{Mime, Status},
30+
Response,
31+
},
32+
Client, Error,
33+
};
34+
35+
fn main() -> ExitCode {
36+
Client::new().request_async(
37+
Uri::parse("gemini://geminiprotocol.net/", UriFlags::NONE).unwrap(),
38+
Priority::DEFAULT,
39+
Cancellable::new(),
40+
None, // optional `GTlsCertificate`
41+
|result: Result<Response, Error>| match result {
42+
Ok(response) => {
43+
match response.meta.status {
44+
// route by status code
45+
Status::Success => match response.meta.mime {
46+
// handle `GIOStream` by content type
47+
Some(Mime::TextGemini) => todo!(),
48+
_ => todo!(),
49+
},
50+
_ => todo!(),
51+
}
52+
}
53+
Err(e) => todo!("{e}"),
54+
},
55+
);
56+
ExitCode::SUCCESS
57+
}
58+
```
59+
2160
## See also
2261

2362
* [ggemtext](https://github.com/YGGverse/ggemtext) - Glib-oriented Gemtext API

0 commit comments

Comments
 (0)