[PATCH] add test and changelog

This commit is contained in:
Rob Ede 2021-11-15 11:27:27 +03:00 committed by Alexander Polakov
parent b30ce27769
commit 05b479f51e
2 changed files with 19 additions and 10 deletions

View File

@ -1,6 +1,9 @@
# Changes # Changes
## Unreleased - 2021-xx-xx ## Unreleased - 2021-xx-xx
* Add `Connect::request` for getting a reference to the connection request. [#415]
[#415]: https://github.com/actix/actix-net/pull/415
## 3.0.0-beta.7 - 2021-10-20 ## 3.0.0-beta.7 - 2021-10-20

View File

@ -63,16 +63,16 @@ impl From<Option<SocketAddr>> for ConnectAddrs {
/// Connection info. /// Connection info.
#[derive(Debug, PartialEq, Eq, Hash)] #[derive(Debug, PartialEq, Eq, Hash)]
pub struct Connect<T> { pub struct Connect<R> {
pub(crate) req: T, pub(crate) req: R,
pub(crate) port: u16, pub(crate) port: u16,
pub(crate) addr: ConnectAddrs, pub(crate) addr: ConnectAddrs,
pub(crate) local_addr: Option<IpAddr>, pub(crate) local_addr: Option<IpAddr>,
} }
impl<T: Address> Connect<T> { impl<R: Address> Connect<R> {
/// Create `Connect` instance by splitting the string by ':' and convert the second part to u16 /// Create `Connect` instance by splitting the string by ':' and convert the second part to u16
pub fn new(req: T) -> Connect<T> { pub fn new(req: R) -> Connect<R> {
let (_, port) = parse_host(req.hostname()); let (_, port) = parse_host(req.hostname());
Connect { Connect {
@ -85,7 +85,7 @@ impl<T: Address> Connect<T> {
/// Create new `Connect` instance from host and address. Connector skips name resolution stage /// Create new `Connect` instance from host and address. Connector skips name resolution stage
/// for such connect messages. /// for such connect messages.
pub fn with_addr(req: T, addr: SocketAddr) -> Connect<T> { pub fn with_addr(req: R, addr: SocketAddr) -> Connect<R> {
Connect { Connect {
req, req,
port: 0, port: 0,
@ -156,19 +156,19 @@ impl<T: Address> Connect<T> {
} }
} }
/// Get request. /// Returns a reference to the connection request.
pub fn request(&self) -> &T { pub fn request(&self) -> &R {
&self.req &self.req
} }
} }
impl<T: Address> From<T> for Connect<T> { impl<R: Address> From<R> for Connect<R> {
fn from(addr: T) -> Self { fn from(addr: R) -> Self {
Connect::new(addr) Connect::new(addr)
} }
} }
impl<T: Address> fmt::Display for Connect<T> { impl<R: Address> fmt::Display for Connect<R> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}", self.hostname(), self.port()) write!(f, "{}:{}", self.hostname(), self.port())
} }
@ -352,4 +352,10 @@ mod tests {
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)) IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))
) )
} }
#[test]
fn request_ref() {
let conn = Connect::new("hello");
assert_eq!(conn.request(), &"hello")
}
} }