1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

fix style

This commit is contained in:
Nathan Fox 2018-04-22 11:43:47 -04:00
parent b7b61afacc
commit f8b75c157f
2 changed files with 40 additions and 40 deletions

View File

@ -29,21 +29,21 @@ impl Frame {
/// Create a new Close control frame. /// Create a new Close control frame.
#[inline] #[inline]
pub fn close(reason: Option<CloseReason>, genmask: bool) -> Binary { pub fn close(reason: Option<CloseReason>, genmask: bool) -> Binary {
let payload = match reason { let payload = match reason {
None => Vec::new(), None => Vec::new(),
Some(reason) => { Some(reason) => {
let mut code_bytes = [0; 2]; let mut code_bytes = [0; 2];
NetworkEndian::write_u16(&mut code_bytes, reason.code.into()); NetworkEndian::write_u16(&mut code_bytes, reason.code.into());
let mut payload = Vec::from(&code_bytes[..]); let mut payload = Vec::from(&code_bytes[..]);
if let Some(description) = reason.description{ if let Some(description) = reason.description{
payload.extend(description.as_bytes()); payload.extend(description.as_bytes());
} }
payload payload
} }
}; };
Frame::message(payload, OpCode::Close, true, genmask) Frame::message(payload, OpCode::Close, true, genmask)
} }
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
@ -529,19 +529,19 @@ mod tests {
assert_eq!(frame, v.into()); assert_eq!(frame, v.into());
} }
#[test] #[test]
fn test_close_frame() { fn test_close_frame() {
let reason = (CloseCode::Normal, "data"); let reason = (CloseCode::Normal, "data");
let frame = Frame::close(Some(reason.into()), false); let frame = Frame::close(Some(reason.into()), false);
let mut v = vec![136u8, 6u8, 3u8, 232u8]; let mut v = vec![136u8, 6u8, 3u8, 232u8];
v.extend(b"data"); v.extend(b"data");
assert_eq!(frame, v.into()); assert_eq!(frame, v.into());
} }
#[test] #[test]
fn test_empty_close_frame() { fn test_empty_close_frame() {
let frame = Frame::close(None, false); let frame = Frame::close(None, false);
assert_eq!(frame, vec![0x88, 0x00].into()); assert_eq!(frame, vec![0x88, 0x00].into());
} }
} }

View File

@ -181,26 +181,26 @@ impl From<u16> for CloseCode {
#[derive(Debug, Eq, PartialEq, Clone)] #[derive(Debug, Eq, PartialEq, Clone)]
pub struct CloseReason { pub struct CloseReason {
pub code: CloseCode, pub code: CloseCode,
pub description: Option<String>, pub description: Option<String>,
} }
impl From<CloseCode> for CloseReason { impl From<CloseCode> for CloseReason {
fn from(code: CloseCode) -> Self { fn from(code: CloseCode) -> Self {
CloseReason { CloseReason {
code, code,
description: None, description: None,
} }
} }
} }
impl <T: Into<String>> From<(CloseCode, T)> for CloseReason { impl <T: Into<String>> From<(CloseCode, T)> for CloseReason {
fn from(info: (CloseCode, T)) -> Self { fn from(info: (CloseCode, T)) -> Self {
CloseReason{ CloseReason{
code: info.0, code: info.0,
description: Some(info.1.into()) description: Some(info.1.into())
} }
} }
} }
static WS_GUID: &'static str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; static WS_GUID: &'static str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";