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

View File

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