Crate gmi[][src]

Expand description

A crate for dealing with the Gemini (and Mercury) protocol

This crate is split into four parts:

The gemtext module is used purely for the parsing of gemtext. The protocol module is used for accessing and parsing various structures to implement the gemini protocol. This module does not use networking The request module is used for actually making requests using std::net. This can be disabled by disabling the feature flag net. The url module is used for manipulating URLs and only contains the areas of the URL specification that Gemini requires.

Example

use gmi::*;
use std::convert::TryFrom;
fn main() -> Result<(), request::RequestError> {
    let test_url = "gemini://gemini.circumlunar.space";
    let mut test_url = url::Url::try_from(test_url).unwrap();
    println!("Making response with URL: {}", test_url);
    loop {
        let response = request::make_request(&test_url)?;
        match response.status {
            protocol::StatusCode::Redirect(c) => {
                println!("Redirect! Code: {} with meta {}", c, response.meta);
                test_url = url::Url::try_from(response.meta.as_str()).unwrap();
                println!("New URL: {}", test_url);
            }
            protocol::StatusCode::Success(c) => {
                println!("Success! Code: {} with MIME type: {}", c, response.meta);
                println!("{}", String::from_utf8_lossy(&response.data));
                break;
            },
            s => panic!("Unknown status code: {:?}", s),
        }
    }
 
    return Ok(())
}

Modules

A gemtext parser

A module for parsing the protocol of Gemini itself. This includes its requests and responses. This module does NOT require any networking stuff. You can disable the request module by disabling the feature flag net.

A library for making requests to gemini servers and parsing reponses. This library requires acccess to std::net and rustls. If you cannot use or do not need these dependencies, you can disable them by disabling the net feature flag.

A URL Library made specifically for Gemini clients