mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
add usage example
This commit is contained in:
parent
d313f900ba
commit
a77e4abf50
1 changed files with 39 additions and 0 deletions
39
README.md
39
README.md
|
|
@ -18,6 +18,45 @@ cargo add ggemini
|
|||
|
||||
* [Documentation](https://docs.rs/ggemini/latest/ggemini/)
|
||||
|
||||
### Example
|
||||
|
||||
``` rust
|
||||
use gtk::gio::*;
|
||||
use gtk::glib::*;
|
||||
|
||||
use ggemini::client::{
|
||||
connection::{
|
||||
response::meta::{Mime, Status},
|
||||
Response,
|
||||
},
|
||||
Client, Error,
|
||||
};
|
||||
|
||||
fn main() -> ExitCode {
|
||||
Client::new().request_async(
|
||||
Uri::parse("gemini://geminiprotocol.net/", UriFlags::NONE).unwrap(),
|
||||
Priority::DEFAULT,
|
||||
Cancellable::new(),
|
||||
None, // optional `GTlsCertificate`
|
||||
|result: Result<Response, Error>| match result {
|
||||
Ok(response) => {
|
||||
match response.meta.status {
|
||||
// route by status code
|
||||
Status::Success => match response.meta.mime {
|
||||
// handle `GIOStream` by content type
|
||||
Some(Mime::TextGemini) => todo!(),
|
||||
_ => todo!(),
|
||||
},
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
Err(e) => todo!("{e}"),
|
||||
},
|
||||
);
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
* [ggemtext](https://github.com/YGGverse/ggemtext) - Glib-oriented Gemtext API
|
||||
Loading…
Add table
Add a link
Reference in a new issue