fingers

Finger client library in Rust
Log | Files | Refs | README | LICENSE

commit 3a47f94888a4b045543171b52cf6fccd438b2dd0
parent 415049204a7c3d958b60ed601ad5daaa3fc4566c
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed,  1 Dec 2021 23:29:00 -0800

Cleanup docs further

Diffstat:
Msrc/lib.rs | 30+++++++++++-------------------
1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs @@ -1,7 +1,8 @@ //! A finger client library //! //! See [RFC 1288](https://datatracker.ietf.org/doc/html/rfc1288), which this library loosely -//! implements +//! implements. The main difference is that it parses requests and responses as UTF-8 instead of +//! (extended) ASCII. //! //! Be mature. //! @@ -32,6 +33,7 @@ impl From<std::io::Error> for Error { } } +/// A request object, with configuration parameters pub struct Request { query: String, host: String, @@ -39,20 +41,6 @@ pub struct Request { max_response_len: Option<u64>, } -/// Builds a URL -/// -/// From the draft spec: -/// https://datatracker.ietf.org/doc/html/draft-ietf-uri-url-finger-02 -pub fn from_url(url: &str) -> Result<Request, Error> { - if url.starts_with("finger://") { - let i = url[9..].find("/").unwrap_or(url.len() - 9); - let host = &url[9..9 + i]; - let query = &url[9 + i..].trim_matches('/'); - return Ok(finger(query, host)); - } - return Err(Error::InvalidFingerURL); -} - /// Build a finger request /// /// rfc1288 2.2 is ignored, queries are UTF-8 strings. @@ -60,6 +48,8 @@ pub fn from_url(url: &str) -> Result<Request, Error> { pub fn finger(query: &str, host: &str) -> Request { let mut q = String::new(); q.push_str(query); + + // Fix query if CRLF was omitted if !q.ends_with("\r\n") { q.push_str("\r\n") } @@ -73,13 +63,15 @@ pub fn finger(query: &str, host: &str) -> Request { } impl Request { - pub fn timeout(mut self, timeout: Option<u64>) -> Request { - self.timeout = timeout; + /// Set timeout. Default is no timeout. + pub fn timeout(mut self, timeout: u64) -> Request { + self.timeout = Some(timeout); self } - pub fn max_response_len(mut self, mrl: Option<u64>) -> Request { - self.max_response_len = mrl; + /// Set max bytes to read before closing connection. Default is no limit. + pub fn max_response_len(mut self, max: u64) -> Request { + self.max_response_len = Some(max); self }