From e20f8f6d9d75ac7f130153c2f9c9b240da1ec00b Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Sun, 12 Mar 2023 19:42:50 +0100 Subject: [PATCH] Reformat, docs --- rust/examples/echo_client.rs | 2 +- rust/examples/echo_server.rs | 8 ++++++-- rust/src/lib.rs | 13 ++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/rust/examples/echo_client.rs b/rust/examples/echo_client.rs index 288245c..1da8a1a 100644 --- a/rust/examples/echo_client.rs +++ b/rust/examples/echo_client.rs @@ -1,6 +1,6 @@ use std::{env, io::Write}; -use tsnet::{ServerBuilder, Network}; +use tsnet::{Network, ServerBuilder}; fn main() { let target = env::args() diff --git a/rust/examples/echo_server.rs b/rust/examples/echo_server.rs index 773b892..b256351 100644 --- a/rust/examples/echo_server.rs +++ b/rust/examples/echo_server.rs @@ -4,11 +4,15 @@ use std::{ thread, }; -use tsnet::{ServerBuilder, Network}; +use tsnet::{Network, ServerBuilder}; fn main() { env_logger::init(); - let ts = ServerBuilder::new().ephemeral().redirect_log().build().unwrap(); + let ts = ServerBuilder::new() + .ephemeral() + .redirect_log() + .build() + .unwrap(); let ln = ts.listen(Network::Tcp, ":1999").unwrap(); for conn in ln { diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 797ac17..245d450 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -49,7 +49,9 @@ //! write!(conn, "This is a test of the Tailscale connection service.\n").unwrap(); //! } //! ``` -#[deny(missing_docs)] +#![deny(missing_docs)] +#![allow(clippy::needless_doctest_main)] + #[allow(non_camel_case_types, dead_code)] mod sys; @@ -95,6 +97,7 @@ pub enum Error { NullInString(#[from] std::ffi::NulError), } +/// A Result, returning either a value or an error, defaulting to the crate error. pub type Result = std::result::Result; /// The possible network types. @@ -424,6 +427,10 @@ pub struct Listener { } impl Listener { + /// Accept a new incoming connection from this listener. + /// + /// This function will block the calling thread until a new connection is established. + /// When established, the corresponding `TcpStream` will be returned. pub fn accept(&self) -> Result { unsafe { let mut conn = 0; @@ -435,10 +442,6 @@ impl Listener { res.map(|_| TcpStream::from_raw_fd(conn)) } } - - pub fn incoming(&mut self) -> &Self { - self - } } impl Drop for Listener {