Skip to content

Commit 10a0d3e

Browse files
author
Jonathan Pallant (42 Technology)
committed
Cleaning up clippy lints.
1 parent ce2562d commit 10a0d3e

File tree

7 files changed

+44
-48
lines changed

7 files changed

+44
-48
lines changed

src/dtls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl DtlsSocket {
160160
sin_len: core::mem::size_of::<sys::nrf_sockaddr_in>() as u8,
161161
sin_family: sys::NRF_AF_INET as i32,
162162
sin_port: htons(port),
163-
sin_addr: dns_addr.sin_addr.clone(),
163+
sin_addr: dns_addr.sin_addr,
164164
};
165165

166166
debug!("Trying IP address {}", &crate::NrfSockAddrIn(connect_addr));

src/gnss.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub enum GnssData {
5050
}
5151

5252
/// Specifies which NMEA fields you want from the GNSS sub-system.
53-
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
53+
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
5454
pub struct NmeaMask(u16);
5555

5656
/// The specific fields you can enable or disable in an `NmeaMask`.
@@ -70,7 +70,7 @@ pub enum NmeaField {
7070
}
7171

7272
/// Specifies which non-volatile fields you want to delete before starting the GNSS.
73-
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
73+
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
7474
pub struct DeleteMask(u32);
7575

7676
/// The specific fields you can enable or disable in a `DeleteMask`.

src/lib.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ pub enum Error {
112112
TooManySockets,
113113
}
114114

115+
/// We need to wrap our heap so it's creatable at run-time and accessible from an ISR.
116+
///
117+
/// * The Mutex allows us to safely share the heap between interrupt routines
118+
/// and the main thread - and nrfxlib will definitely use the heap in an
119+
/// interrupt.
120+
/// * The RefCell lets us share and object and mutate it (but not at the same
121+
/// time)
122+
/// * The Option is because the `linked_list_allocator::empty()` function is not
123+
/// `const` yet and cannot be called here
124+
///
125+
type WrappedHeap = Mutex<RefCell<Option<Heap>>>;
126+
115127
//******************************************************************************
116128
// Constants
117129
//******************************************************************************
@@ -124,30 +136,14 @@ pub enum Error {
124136

125137
/// Our general heap.
126138
///
127-
/// * The Mutex allows us to safely share the heap between interrupt routines
128-
/// and the main thread - and nrfxlib will definitely use the heap in an
129-
/// interrupt.
130-
/// * The RefCell lets us share and object and mutate it (but not at the same
131-
/// time)
132-
/// * The Option is because the `linked_list_allocator::empty()` function is not
133-
/// `const` yet and cannot be called here
134-
///
135-
/// We initialise it later a static variable as the backing store.
136-
static mut GENERIC_ALLOCATOR: Mutex<RefCell<Option<Heap>>> = Mutex::new(RefCell::new(None));
139+
/// We initialise it later with a static variable as the backing store.
140+
static LIBRARY_ALLOCATOR: WrappedHeap = Mutex::new(RefCell::new(None));
137141

138142
/// Our transmit heap.
139-
///
140-
/// * The Mutex allows us to safely share the heap between interrupt routines
141-
/// and the main thread - and nrfxlib will definitely use the heap in an
142-
/// interrupt.
143-
/// * The RefCell lets us share and object and mutate it (but not at the same
144-
/// time)
145-
/// * The Option is because the `linked_list_allocator::empty()` function is not
146-
/// `const` yet and cannot be called here
147-
///
143+
148144
/// We initalise this later using a special region of shared memory that can be
149145
/// seen by the Cortex-M33 and the modem CPU.
150-
static mut TX_ALLOCATOR: Mutex<RefCell<Option<Heap>>> = Mutex::new(RefCell::new(None));
146+
static TX_ALLOCATOR: WrappedHeap = Mutex::new(RefCell::new(None));
151147

152148
//******************************************************************************
153149
// Macros
@@ -167,7 +163,7 @@ pub fn init() -> Result<(), Error> {
167163
let heap_start = HEAP_MEMORY.as_ptr() as usize;
168164
let heap_size = HEAP_MEMORY.len() * core::mem::size_of::<u32>();
169165
cortex_m::interrupt::free(|cs| {
170-
*GENERIC_ALLOCATOR.borrow(cs).borrow_mut() = Some(Heap::new(heap_start, heap_size))
166+
*LIBRARY_ALLOCATOR.borrow(cs).borrow_mut() = Some(Heap::new(heap_start, heap_size))
171167
});
172168
}
173169

src/raw.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -306,31 +306,31 @@ impl<'a> SocketOption<'a> {
306306
}
307307
}
308308

309-
impl Into<i32> for SocketDomain {
310-
fn into(self) -> i32 {
309+
impl From<SocketDomain> for i32 {
310+
fn from(s: SocketDomain) -> i32 {
311311
use SocketDomain::*;
312-
match self {
312+
match s {
313313
Local => sys::NRF_AF_LOCAL as i32,
314314
Lte => sys::NRF_AF_LTE as i32,
315315
Inet => sys::NRF_AF_INET as i32,
316316
}
317317
}
318318
}
319319

320-
impl Into<i32> for SocketType {
321-
fn into(self) -> i32 {
320+
impl From<SocketType> for i32 {
321+
fn from(s: SocketType) -> i32 {
322322
use SocketType::*;
323-
match self {
323+
match s {
324324
Stream => sys::NRF_SOCK_STREAM as i32,
325325
Datagram => sys::NRF_SOCK_DGRAM as i32,
326326
}
327327
}
328328
}
329329

330-
impl Into<i32> for SocketProtocol {
331-
fn into(self) -> i32 {
330+
impl From<SocketProtocol> for i32 {
331+
fn from(s: SocketProtocol) -> i32 {
332332
use SocketProtocol::*;
333-
match self {
333+
match s {
334334
At => sys::NRF_PROTO_AT as i32,
335335
Tcp => sys::NRF_IPPROTO_TCP as i32,
336336
Udp => sys::NRF_IPPROTO_UDP as i32,
@@ -408,19 +408,19 @@ impl<'a> PollEntry<'a> {
408408
/// let mut socket1 = AtSocket::new();
409409
/// let mut socket2 = GnssSocket::new();
410410
/// let mut poll_list = [
411-
/// PollEntry::new(&mut socket1, PollFlags::Read),
412-
/// PollEntry::new(&mut socket2, PollFlags::Read),
411+
/// PollEntry::new(&mut socket1, PollFlags::Read),
412+
/// PollEntry::new(&mut socket2, PollFlags::Read),
413413
/// ];
414414
/// match nrfxlib::poll(&mut poll_list, 100) {
415-
/// Ok(0) => {
416-
/// // Timeout
417-
/// }
418-
/// Ok(n) => {
419-
/// // One of the sockets is ready. See `poll_list[n].result()`.
420-
/// }
421-
/// Err(e) => {
422-
/// // An error occurred
423-
/// }
415+
/// Ok(0) => {
416+
/// // Timeout
417+
/// }
418+
/// Ok(n) => {
419+
/// // One of the sockets is ready. See `poll_list[n].result()`.
420+
/// }
421+
/// Err(e) => {
422+
/// // An error occurred
423+
/// }
424424
/// }
425425
/// ```
426426
pub fn poll(poll_list: &mut [PollEntry], timeout_ms: u16) -> Result<i32, Error> {
@@ -462,7 +462,7 @@ pub fn poll(poll_list: &mut [PollEntry], timeout_ms: u16) -> Result<i32, Error>
462462

463463
pub(crate) fn htons(input: u16) -> u16 {
464464
let top: u16 = (input >> 8) & 0xFF;
465-
let bottom: u16 = (input >> 0) & 0xFF;
465+
let bottom: u16 = input & 0xFF;
466466
(bottom << 8) | top
467467
}
468468

src/tcp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl TcpSocket {
114114
sin_len: core::mem::size_of::<sys::nrf_sockaddr_in>() as u8,
115115
sin_family: sys::NRF_AF_INET as i32,
116116
sin_port: htons(port),
117-
sin_addr: dns_addr.sin_addr.clone(),
117+
sin_addr: dns_addr.sin_addr,
118118
};
119119

120120
debug!("Trying IP address {}", &crate::NrfSockAddrIn(connect_addr));

src/tls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl TlsSocket {
173173
sin_len: core::mem::size_of::<sys::nrf_sockaddr_in>() as u8,
174174
sin_family: sys::NRF_AF_INET as i32,
175175
sin_port: htons(port),
176-
sin_addr: dns_addr.sin_addr.clone(),
176+
sin_addr: dns_addr.sin_addr,
177177
};
178178

179179
debug!("Trying IP address {}", &crate::NrfSockAddrIn(connect_addr));

src/udp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl UdpSocket {
118118
sin_len: core::mem::size_of::<sys::nrf_sockaddr_in>() as u8,
119119
sin_family: sys::NRF_AF_INET as i32,
120120
sin_port: htons(port),
121-
sin_addr: dns_addr.sin_addr.clone(),
121+
sin_addr: dns_addr.sin_addr,
122122
};
123123

124124
debug!("Trying IP address {}", &crate::NrfSockAddrIn(connect_addr));

0 commit comments

Comments
 (0)