Skip to content
This repository has been archived by the owner on Aug 17, 2020. It is now read-only.

Commit

Permalink
make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
lschmierer committed Apr 20, 2018
1 parent afb26dd commit b4121be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
51 changes: 24 additions & 27 deletions src/packet.rs
Expand Up @@ -48,8 +48,8 @@
//! # }}
//! ```

use core::str;
use core::hash::{self, Hash};
use core::str;
#[cfg(feature = "std")]
use std::borrow::Cow;
#[cfg(feature = "std")]
Expand All @@ -64,21 +64,21 @@ use error::{PackError, ParseError};

#[inline]
fn zeros(buf: &mut [u8], n: usize) {
for i in 0..n {
buf[i] = 0;
for b in buf.iter_mut().take(n) {
*b = 0;
}
}

#[inline]
fn parse_c_str(buf: &[u8]) -> Result<&str, ParseError> {
let mut source_name_len = buf.len();
for i in 0..buf.len() {
if buf[i] == 0 {
source_name_len = i;
let mut source_name_length = buf.len();
for (i, b) in buf.iter().enumerate() {
if *b == 0 {
source_name_length = i;
break;
}
}
Ok(str::from_utf8(&buf[..source_name_len])?)
Ok(str::from_utf8(&buf[..source_name_length])?)
}

macro_rules! impl_acn_root_layer_protocol {
Expand Down Expand Up @@ -210,8 +210,8 @@ trait Pdu: Sized {
fn len(&self) -> usize;
}

const VECTOR_ROOT_E131_DATA: u32 = 0x00000004;
const VECTOR_ROOT_E131_EXTENDED: u32 = 0x00000008;
const VECTOR_ROOT_E131_DATA: u32 = 0x0000_0004;
const VECTOR_ROOT_E131_EXTENDED: u32 = 0x0000_0008;

macro_rules! impl_e131_root_layer {
( $( $lt:tt )* ) => {
Expand Down Expand Up @@ -256,12 +256,9 @@ macro_rules! impl_e131_root_layer {
}
VECTOR_ROOT_E131_EXTENDED => {
let data_buf = &buf[22..length];
let PduInfo {
length: _,
vector: data_vector,
} = pdu_info(&data_buf, 4)?;
let PduInfo { vector, .. } = pdu_info(&data_buf, 4)?;

match data_vector {
match vector {
VECTOR_E131_EXTENDED_SYNCHRONIZATION => {
E131RootLayerData::SynchronizationPacket(
SynchronizationPacketFramingLayer::parse(data_buf)?,
Expand Down Expand Up @@ -338,7 +335,7 @@ impl_e131_root_layer!(<'a>);
#[cfg(not(feature = "std"))]
impl_e131_root_layer!();

const VECTOR_E131_DATA_PACKET: u32 = 0x00000002;
const VECTOR_E131_DATA_PACKET: u32 = 0x0000_0002;

macro_rules! impl_data_packet_framing_layer {
( $( $lt:tt )* ) => {
Expand Down Expand Up @@ -397,9 +394,9 @@ macro_rules! impl_data_packet_framing_layer {
let sequence_number = buf[73];

// Options
let preview_data = buf[74] & 0b01000000 != 0;
let stream_terminated = buf[74] & 0b00100000 != 0;
let force_synchronization = buf[74] & 0b00010000 != 0;
let preview_data = buf[74] & 0b0100_0000 != 0;
let stream_terminated = buf[74] & 0b0010_0000 != 0;
let force_synchronization = buf[74] & 0b0001_0000 != 0;

// Universe
let universe = NetworkEndian::read_u16(&buf[75..77]);
Expand Down Expand Up @@ -453,17 +450,17 @@ macro_rules! impl_data_packet_framing_layer {

// Preview Data
if self.preview_data {
buf[74] = 0b01000000
buf[74] = 0b0100_0000
}

// Stream Terminated
if self.stream_terminated {
buf[74] |= 0b00100000
buf[74] |= 0b0010_0000
}

// Force Synchronization
if self.force_synchronization {
buf[74] |= 0b00010000
buf[74] |= 0b0001_0000
}

// Universe
Expand Down Expand Up @@ -557,7 +554,7 @@ macro_rules! impl_data_packet_dmp_layer {
fn parse(buf: &[u8]) -> Result<DataPacketDmpLayer$( $lt )*, ParseError> {
// Length and Vector
let PduInfo { length, vector } = pdu_info(&buf, 1)?;
if vector != VECTOR_DMP_SET_PROPERTY as u32 {
if vector != u32::from(VECTOR_DMP_SET_PROPERTY) {
return Err(ParseError::PduInvalidVector(vector));
}

Expand Down Expand Up @@ -689,7 +686,7 @@ impl_data_packet_dmp_layer!(<'a>);
#[cfg(not(feature = "std"))]
impl_data_packet_dmp_layer!();

const VECTOR_E131_EXTENDED_SYNCHRONIZATION: u32 = 0x00000001;
const VECTOR_E131_EXTENDED_SYNCHRONIZATION: u32 = 0x0000_0001;

/// sACN synchronization packet PDU.
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
Expand All @@ -704,7 +701,7 @@ pub struct SynchronizationPacketFramingLayer {
impl Pdu for SynchronizationPacketFramingLayer {
fn parse(buf: &[u8]) -> Result<SynchronizationPacketFramingLayer, ParseError> {
// Length and Vector
let PduInfo { length: _, vector } = pdu_info(&buf, 4)?;
let PduInfo { vector, .. } = pdu_info(&buf, 4)?;
if vector != VECTOR_E131_EXTENDED_SYNCHRONIZATION {
return Err(ParseError::PduInvalidVector(vector));
}
Expand Down Expand Up @@ -764,7 +761,7 @@ impl Pdu for SynchronizationPacketFramingLayer {
}
}

const VECTOR_E131_EXTENDED_DISCOVERY: u32 = 0x00000002;
const VECTOR_E131_EXTENDED_DISCOVERY: u32 = 0x0000_0002;

macro_rules! impl_universe_discovery_packet_framing_layer {
( $( $lt:tt )* ) => {
Expand Down Expand Up @@ -874,7 +871,7 @@ impl_universe_discovery_packet_framing_layer!(<'a>);
#[cfg(not(feature = "std"))]
impl_universe_discovery_packet_framing_layer!();

const VECTOR_UNIVERSE_DISCOVERY_UNIVERSE_LIST: u32 = 0x00000001;
const VECTOR_UNIVERSE_DISCOVERY_UNIVERSE_LIST: u32 = 0x0000_0001;

macro_rules! impl_universe_discovery_packet_universe_discovery_layer {
( $( $lt:tt )* ) => {
Expand Down
16 changes: 8 additions & 8 deletions src/source.rs
Expand Up @@ -75,12 +75,12 @@ impl DmxSource {
/// Constructs a new DmxSource with DMX START code set to 0 with specified CID and IP address.
pub fn with_cid_ip(name: &str, cid: Uuid, ip: &str) -> Result<DmxSource> {
let ip_port = format!("{}:0", ip);
let sock_builder = try!(UdpBuilder::new_v4());
let sock = try!(sock_builder.bind(&ip_port));
let socket_builder = try!(UdpBuilder::new_v4());
let socket = try!(socket_builder.bind(&ip_port));

Ok(DmxSource {
socket: sock,
cid: cid.clone(),
socket,
cid,
name: name.to_string(),
preview_data: false,
start_code: 0,
Expand All @@ -103,7 +103,7 @@ impl DmxSource {
}
let ip = try!(universe_to_ip(universe));
let mut sequence = match self.sequences.borrow().get(&universe) {
Some(s) => s.clone(),
Some(s) => *s,
None => 0,
};

Expand All @@ -112,13 +112,13 @@ impl DmxSource {
cid: self.cid,
data: E131RootLayerData::DataPacket(DataPacketFramingLayer {
source_name: self.name.as_str().into(),
priority: priority,
priority,
synchronization_address: 0,
sequence_number: sequence,
preview_data: self.preview_data,
stream_terminated: false,
force_synchronization: false,
universe: universe,
universe,
data: DataPacketDmpLayer {
property_values: {
let mut property_values = Vec::with_capacity(data.len() + 1);
Expand Down Expand Up @@ -164,7 +164,7 @@ impl DmxSource {
preview_data: self.preview_data,
stream_terminated: true,
force_synchronization: false,
universe: universe,
universe,
data: DataPacketDmpLayer {
property_values: vec![self.start_code].into(),
},
Expand Down

0 comments on commit b4121be

Please sign in to comment.