Skip to content

Commit

Permalink
Merge pull request #184 from embassy-rs/fix-elided
Browse files Browse the repository at this point in the history
Fix build errors for elided lifetimes
  • Loading branch information
lulf authored Nov 29, 2024
2 parents 04d10fd + 98f54e0 commit 1bd7722
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 70 deletions.
4 changes: 2 additions & 2 deletions host/src/advertise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub(crate) struct RawAdvertisement<'d> {
pub(crate) peer: Option<Address>,
}

impl<'d> Default for RawAdvertisement<'d> {
impl Default for RawAdvertisement<'_> {
fn default() -> Self {
Self {
props: AdvEventProps::new()
Expand Down Expand Up @@ -403,7 +403,7 @@ pub enum AdStructure<'a> {
},
}

impl<'d> AdStructure<'d> {
impl AdStructure<'_> {
/// Encode a slice of advertisement structures into a buffer.
pub fn encode_slice(data: &[AdStructure<'_>], dest: &mut [u8]) -> Result<usize, codec::Error> {
let mut w = WriteCursor::new(dest);
Expand Down
10 changes: 5 additions & 5 deletions host/src/att.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ pub enum AttRsp<'d> {
Write,
}

impl<'d> codec::Type for AttRsp<'d> {
impl codec::Type for AttRsp<'_> {
fn size(&self) -> usize {
AttRsp::size(self)
}
}

impl<'d> codec::Encode for AttRsp<'d> {
impl codec::Encode for AttRsp<'_> {
fn encode(&self, dest: &mut [u8]) -> Result<(), codec::Error> {
AttRsp::encode(self, dest)
}
Expand All @@ -196,7 +196,7 @@ pub struct FindByTypeValueIter<'d> {
cursor: ReadCursor<'d>,
}

impl<'d> FindByTypeValueIter<'d> {
impl FindByTypeValueIter<'_> {
pub fn next(&mut self) -> Option<Result<(u16, u16), crate::Error>> {
if self.cursor.available() >= 4 {
let res = (|| {
Expand Down Expand Up @@ -325,13 +325,13 @@ impl From<codec::Error> for AttErrorCode {
}
}

impl<'d> codec::Type for AttReq<'d> {
impl codec::Type for AttReq<'_> {
fn size(&self) -> usize {
AttReq::size(self)
}
}

impl<'d> codec::Encode for AttReq<'d> {
impl codec::Encode for AttReq<'_> {
fn encode(&self, dest: &mut [u8]) -> Result<(), codec::Error> {
AttReq::encode(self, dest)
}
Expand Down
16 changes: 8 additions & 8 deletions host/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub(crate) enum AttributeData<'d> {
},
}

impl<'d> AttributeData<'d> {
impl AttributeData<'_> {
pub(crate) fn readable(&self) -> bool {
match self {
Self::Data { props, value } => props.0 & (CharacteristicProp::Read as u8) != 0,
Expand Down Expand Up @@ -256,7 +256,7 @@ impl<'d> AttributeData<'d> {
}
}

impl<'a> fmt::Debug for Attribute<'a> {
impl fmt::Debug for Attribute<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Attribute")
.field("uuid", &self.uuid)
Expand Down Expand Up @@ -314,7 +314,7 @@ impl<'d, const MAX: usize> InnerTable<'d, MAX> {
}
}

impl<'d, M: RawMutex, const MAX: usize> Default for AttributeTable<'d, M, MAX> {
impl<M: RawMutex, const MAX: usize> Default for AttributeTable<'_, M, MAX> {
fn default() -> Self {
Self::new()
}
Expand Down Expand Up @@ -509,7 +509,7 @@ pub struct ServiceBuilder<'r, 'd, M: RawMutex, const MAX: usize> {
table: &'r mut AttributeTable<'d, M, MAX>,
}

impl<'r, 'd, M: RawMutex, const MAX: usize> ServiceBuilder<'r, 'd, M, MAX> {
impl<'d, M: RawMutex, const MAX: usize> ServiceBuilder<'_, 'd, M, MAX> {
fn add_characteristic_internal<T: GattValue>(
&mut self,
uuid: Uuid,
Expand Down Expand Up @@ -609,7 +609,7 @@ impl<'r, 'd, M: RawMutex, const MAX: usize> ServiceBuilder<'r, 'd, M, MAX> {
}
}

impl<'r, 'd, M: RawMutex, const MAX: usize> Drop for ServiceBuilder<'r, 'd, M, MAX> {
impl<M: RawMutex, const MAX: usize> Drop for ServiceBuilder<'_, '_, M, MAX> {
fn drop(&mut self) {
let last_handle = self.table.handle + 1;
self.table.with_inner(|inner| {
Expand Down Expand Up @@ -639,7 +639,7 @@ pub struct CharacteristicBuilder<'r, 'd, T: GattValue, M: RawMutex, const MAX: u
table: &'r mut AttributeTable<'d, M, MAX>,
}

impl<'r, 'd, T: GattValue, M: RawMutex, const MAX: usize> CharacteristicBuilder<'r, 'd, T, M, MAX> {
impl<'d, T: GattValue, M: RawMutex, const MAX: usize> CharacteristicBuilder<'_, 'd, T, M, MAX> {
fn add_descriptor_internal(
&mut self,
uuid: Uuid,
Expand Down Expand Up @@ -727,7 +727,7 @@ pub struct AttributeIterator<'a, 'd> {
len: usize,
}

impl<'a, 'd> AttributeIterator<'a, 'd> {
impl<'d> AttributeIterator<'_, 'd> {
/// Return next attribute in iterator.
pub fn next<'m>(&'m mut self) -> Option<&'m mut Attribute<'d>> {
if self.pos < self.len {
Expand Down Expand Up @@ -794,7 +794,7 @@ pub struct AttributeValue<'d, M: RawMutex> {
value: Mutex<M, &'d mut [u8]>,
}

impl<'d, M: RawMutex> AttributeValue<'d, M> {}
impl<M: RawMutex> AttributeValue<'_, M> {}

/// CCCD flag values.
#[derive(Clone, Copy)]
Expand Down
6 changes: 3 additions & 3 deletions host/src/channel_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'d, const QLEN: usize> PacketChannel<'d, QLEN> {
}
}

impl<'d> State<'d> {
impl State<'_> {
fn print(&self, verbose: bool) {
for (idx, storage) in self.channels.iter().enumerate() {
if verbose || storage.state != ChannelState::Disconnected {
Expand Down Expand Up @@ -800,7 +800,7 @@ pub(crate) trait DynamicChannelManager {
fn print(&self, index: ChannelIndex, f: defmt::Formatter);
}

impl<'d, const RXQ: usize> DynamicChannelManager for ChannelManager<'d, RXQ> {
impl<const RXQ: usize> DynamicChannelManager for ChannelManager<'_, RXQ> {
fn inc_ref(&self, index: ChannelIndex) {
ChannelManager::inc_ref(self, index)
}
Expand Down Expand Up @@ -987,7 +987,7 @@ impl<'reference, 'state> CreditGrant<'reference, 'state> {
}
}

impl<'reference, 'state> Drop for CreditGrant<'reference, 'state> {
impl Drop for CreditGrant<'_, '_> {
fn drop(&mut self) {
if self.credits > 0 {
let mut state = self.state.borrow_mut();
Expand Down
4 changes: 2 additions & 2 deletions host/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ pub struct Connection<'d> {
manager: &'d ConnectionManager<'d>,
}

impl<'d> Clone for Connection<'d> {
impl Clone for Connection<'_> {
fn clone(&self) -> Self {
self.manager.inc_ref(self.index);
Connection::new(self.index, self.manager)
}
}

impl<'d> Drop for Connection<'d> {
impl Drop for Connection<'_> {
fn drop(&mut self) {
self.manager.dec_ref(self.index);
}
Expand Down
6 changes: 3 additions & 3 deletions host/src/connection_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct State<'d> {
default_att_mtu: u16,
}

impl<'d> State<'d> {
impl State<'_> {
fn print(&self, verbose: bool) {
for (idx, storage) in self.connections.iter().enumerate() {
if verbose || storage.state != ConnectionState::Disconnected {
Expand Down Expand Up @@ -422,7 +422,7 @@ pub struct DisconnectRequest<'a, 'd> {
state: &'a RefCell<State<'d>>,
}

impl<'a, 'd> DisconnectRequest<'a, 'd> {
impl DisconnectRequest<'_, '_> {
pub fn handle(&self) -> ConnHandle {
self.handle
}
Expand Down Expand Up @@ -586,7 +586,7 @@ impl<'a, 'd> PacketGrant<'a, 'd> {
}
}

impl<'a, 'd> Drop for PacketGrant<'a, 'd> {
impl Drop for PacketGrant<'_, '_> {
fn drop(&mut self) {
if self.packets > 0 {
let mut state = self.state.borrow_mut();
Expand Down
6 changes: 3 additions & 3 deletions host/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,19 @@ impl<T, E> Try for Result<T, E> {
#[allow(unused)]
pub(crate) struct Bytes<'a>(pub &'a [u8]);

impl<'a> Debug for Bytes<'a> {
impl Debug for Bytes<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:#02x?}", self.0)
}
}

impl<'a> Display for Bytes<'a> {
impl Display for Bytes<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:#02x?}", self.0)
}
}

impl<'a> LowerHex for Bytes<'a> {
impl LowerHex for Bytes<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:#02x?}", self.0)
}
Expand Down
4 changes: 2 additions & 2 deletions host/src/l2cap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct L2capChannel<'d> {
manager: &'d dyn DynamicChannelManager,
}

impl<'d> Clone for L2capChannel<'d> {
impl Clone for L2capChannel<'_> {
fn clone(&self) -> Self {
self.manager.inc_ref(self.index);
L2capChannel::new(self.index, self.manager)
Expand All @@ -29,7 +29,7 @@ impl defmt::Format for L2capChannel<'_> {
}
}

impl<'d> Drop for L2capChannel<'d> {
impl Drop for L2capChannel<'_> {
fn drop(&mut self) {
self.manager.dec_ref(self.index);
}
Expand Down
4 changes: 2 additions & 2 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,10 @@ impl<'d, C: Controller> Stack<'d, C> {
}
}

impl<'d, C> Clone for Stack<'d, C> {
impl<C> Clone for Stack<'_, C> {
fn clone(&self) -> Self {
*self
}
}

impl<'d, C> Copy for Stack<'d, C> {}
impl<C> Copy for Stack<'_, C> {}
4 changes: 2 additions & 2 deletions host/src/pdu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ impl<'d> Pdu<'d> {
}
}

impl<'d> AsRef<[u8]> for Pdu<'d> {
impl AsRef<[u8]> for Pdu<'_> {
fn as_ref(&self) -> &[u8] {
&self.packet.as_ref()[..self.len]
}
}

impl<'d> AsMut<[u8]> for Pdu<'d> {
impl AsMut<[u8]> for Pdu<'_> {
fn as_mut(&mut self) -> &mut [u8] {
&mut self.packet.as_mut()[..self.len]
}
Expand Down
2 changes: 1 addition & 1 deletion host/src/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl<'d, C: Controller> Advertiser<'d, C> {
}
}

impl<'d, C: Controller> Drop for Advertiser<'d, C> {
impl<C: Controller> Drop for Advertiser<'_, C> {
fn drop(&mut self) {
self.stack.host.advertise_command_state.cancel(self.extended);
}
Expand Down
10 changes: 5 additions & 5 deletions host/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct ScanConfig<'d> {
pub timeout: Duration,
}

impl<'d> Default for ScanConfig<'d> {
impl Default for ScanConfig<'_> {
fn default() -> Self {
Self {
active: true,
Expand Down Expand Up @@ -119,13 +119,13 @@ impl<'a> Iterator for ScanReportIter<'a> {
}
}

impl<'a> ExactSizeIterator for ScanReportIter<'a> {
impl ExactSizeIterator for ScanReportIter<'_> {
fn len(&self) -> usize {
self.len
}
}

impl<'a> FusedIterator for ScanReportIter<'a> {}
impl FusedIterator for ScanReportIter<'_> {}

/// Iterator over extended scan reports.
pub struct ExtScanReportIter<'a> {
Expand Down Expand Up @@ -159,10 +159,10 @@ impl<'a> Iterator for ExtScanReportIter<'a> {
}
}

impl<'a> ExactSizeIterator for ExtScanReportIter<'a> {
impl ExactSizeIterator for ExtScanReportIter<'_> {
fn len(&self) -> usize {
self.len
}
}

impl<'a> FusedIterator for ExtScanReportIter<'a> {}
impl FusedIterator for ExtScanReportIter<'_> {}
31 changes: 14 additions & 17 deletions host/tests/gatt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,22 @@ async fn gatt_client_server() {
println!("Disconnected: {:?}", reason);
break;
}
ConnectionEvent::Gatt { connection: _, event } => match event {
GattEvent::Write {
ConnectionEvent::Gatt { connection: _, event } => if let GattEvent::Write {
value_handle: handle
} => {
let characteristic = server.server().table().find_characteristic_by_value_handle(handle).unwrap();
assert_eq!(characteristic, value_handle);
let value: u8 = server.server().table().get(&characteristic).unwrap();
println!("[peripheral] write value: {}", value);
assert_eq!(expected, value);
expected = expected.wrapping_add(1);
writes += 1;
if writes == 2 {
println!("expected value written twice, test pass");
// NOTE: Ensure that adapter gets polled again
tokio::time::sleep(Duration::from_secs(2)).await;
done = true;
}
} = event {
let characteristic = server.server().table().find_characteristic_by_value_handle(handle).unwrap();
assert_eq!(characteristic, value_handle);
let value: u8 = server.server().table().get(&characteristic).unwrap();
println!("[peripheral] write value: {}", value);
assert_eq!(expected, value);
expected = expected.wrapping_add(1);
writes += 1;
if writes == 2 {
println!("expected value written twice, test pass");
// NOTE: Ensure that adapter gets polled again
tokio::time::sleep(Duration::from_secs(2)).await;
done = true;
}
_ => {},
}
}
}
Expand Down
27 changes: 12 additions & 15 deletions host/tests/gatt_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,20 @@ async fn gatt_client_server() {
println!("Disconnected: {:?}", reason);
break;
}
ConnectionEvent::Gatt { event, .. } => match event {
GattEvent::Write {
ConnectionEvent::Gatt { event, .. } => if let GattEvent::Write {
value_handle: handle
} => {
let characteristic = server.server().table().find_characteristic_by_value_handle(handle).unwrap();
let value: u8 = server.server().table().get(&characteristic).unwrap();
assert_eq!(expected, value);
expected = expected.wrapping_add(2);
writes += 1;
if writes == 2 {
println!("expected value written twice, test pass");
// NOTE: Ensure that adapter gets polled again
tokio::time::sleep(Duration::from_secs(2)).await;
done = true;
}
} = event {
let characteristic = server.server().table().find_characteristic_by_value_handle(handle).unwrap();
let value: u8 = server.server().table().get(&characteristic).unwrap();
assert_eq!(expected, value);
expected = expected.wrapping_add(2);
writes += 1;
if writes == 2 {
println!("expected value written twice, test pass");
// NOTE: Ensure that adapter gets polled again
tokio::time::sleep(Duration::from_secs(2)).await;
done = true;
}
_ => {},
}
}
}
Expand Down

0 comments on commit 1bd7722

Please sign in to comment.