titanite 0.2.0

Client/Server Library for Gemini protocol with Titan support
Documentation
pub mod request;
pub mod response;

pub use request::Request;
pub use response::Response;

pub const HEADER_MAX_LEN: usize = 1024;

pub trait Header {
    fn header_bytes(&self) -> Result<&[u8]>;
}

impl Header for &[u8] {
    fn header_bytes(&self) -> Result<&[u8]> {
        match self.iter().position(|&b| b == b'\r') {
            Some(n) => {
                if n > HEADER_MAX_LEN {
                    bail!("Header bytes length reached")
                }
                if self.get(n + 1).is_some_and(|&b| b == b'\n') {
                    Ok(&self[..n])
                } else {
                    bail!("LF byte not found")
                }
            }
            None => bail!("CR byte not found"),
        }
    }
}

use anyhow::{bail, Result};