Skip to main content

Crate nex_protocol

Crate nex_protocol 

Source
Expand description

An implementation of the Nex protocol (nex://, TCP port 1900): an async client, a directory-serving server, a listing parser, and a small CLI.

Nex is the minimal smolweb protocol, from nightfall.city, inspired by gopher and gemini. The whole wire format: the client connects and sends a path (which may be empty); the server responds with text or binary data and closes the connection. No TLS, no status codes, no headers, no state. Directory content is plain text where each line beginning => followed by a URL is a link; an empty path or a path ending in / is a directory; a document’s display type follows its file extension, defaulting to plain text.

This crate is independent and unaffiliated with the protocol’s author. The crates.io name is qualified (nex-protocol) because the bare nex name is used by an unrelated project.

let body = nex_protocol::fetch("nex://nightfall.city/", &Default::default()).await?;
println!("{}", String::from_utf8_lossy(&body));

Structs§

FetchOptions
Options for a fetch.
FileHandler
A static-directory Handler. Directory selectors (empty or trailing /) serve a generated listing, or the directory’s index.nex file when present. Traversal out of the root is refused with a plain-text message.
Request
One nex request: the selector path, exactly as sent (CR/LF trimmed).
ServerConfig
Server limits and timeouts.

Enums§

ClientError
Why a fetch failed. Nex has no protocol-level errors: a successful exchange is whatever bytes the server sent.
ListingLine
One line of a directory listing.

Constants§

NEX_PORT
Nex’s port (“Afterall, night falls at 7pm!”).

Traits§

Handler
The application seam: turn a Request into response bytes. Nex has no status codes, so “not found” is whatever text the handler chooses.

Functions§

fetch
Fetch a nex:// URL and return the raw response bytes.
fetch_path
Fetch by explicit host/port/path. The path may be empty (the spec allows an empty selector for the root).
is_directory_path
Whether a request path names a directory, per the spec: an empty path or one ending in /.
parse_listing
Parse a directory listing into its lines.
serve
Accept connections on listener and serve them through handler until shutdown resolves.