Skip to content

Commit

Permalink
add some docs for internal-only listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr committed Jul 13, 2020
1 parent 7f0849d commit ba65ca4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/listener/parsed_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
use super::UnixListener;
use super::{Listener, TcpListener};
use crate::Server;

use async_std::io;
use std::fmt::{self, Display, Formatter};

/// This is an enum that contains variants for each of the listeners
/// that can be parsed from a string. This is used as the associated
/// Listener type for the string-parsing
/// [ToListener](crate::listener::ToListener) implementations
///
/// This is currently crate-visible only, and tide users are expected
/// to create these through [ToListener](crate::ToListener) conversions.
#[derive(Debug)]
pub enum ParsedListener {
#[cfg(unix)]
Expand Down
10 changes: 9 additions & 1 deletion src/listener/tcp_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ use async_std::net::{self, SocketAddr, TcpStream};
use async_std::prelude::*;
use async_std::{io, task};

/// This represents a tide [Listener](crate::listener::Listener) that
/// wraps an [async_std::net::TcpListener]. It is implemented as an
/// enum in order to allow creation of a tide::listener::TcpListener
/// from a SocketAddr spec that has not yet been bound OR from a bound
/// TcpListener.
///
/// This is currently crate-visible only, and tide users are expected
/// to create these through [ToListener](crate::ToListener) conversions.
#[derive(Debug)]
pub enum TcpListener {
FromListener(net::TcpListener),
Expand All @@ -30,7 +38,7 @@ impl TcpListener {
Self::FromListener(listener) => Ok(listener),
Self::FromAddrs(addrs, None) => Err(io::Error::new(
io::ErrorKind::AddrNotAvailable,
format!("unable to connect {:?}", addrs),
format!("unable to connect to {:?}", addrs),
)),
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/listener/unix_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ use async_std::os::unix::net::{self, SocketAddr, UnixStream};
use async_std::prelude::*;
use async_std::{io, path::PathBuf, task};

/// This represents a tide [Listener](crate::listener::Listener) that
/// wraps an [async_std::os::unix::net::UnixListener]. It is implemented as an
/// enum in order to allow creation of a tide::listener::UnixListener
/// from a [PathBuf] that has not yet been opened/bound OR from a bound
/// [async_std::os::unix::net::UnixListener].
///
/// This is currently crate-visible only, and tide users are expected
/// to create these through [ToListener](crate::ToListener) conversions.
#[derive(Debug)]
pub enum UnixListener {
FromPath(PathBuf, Option<net::UnixListener>),
Expand All @@ -30,7 +38,10 @@ impl UnixListener {
Self::FromListener(listener) => Ok(listener),
Self::FromPath(path, None) => Err(io::Error::new(
io::ErrorKind::AddrNotAvailable,
format!("unable to connect {}", path.to_str().unwrap_or("[unknown]")),
format!(
"unable to connect to {}",
path.to_str().unwrap_or("[unknown]")
),
)),
}
}
Expand Down

0 comments on commit ba65ca4

Please sign in to comment.