Skip to content

Commit 514cd9e

Browse files
committed
Run cargo clippy and cargo fmt
Signed-off-by: Gris Ge <[email protected]>
1 parent b26fc3a commit 514cd9e

File tree

10 files changed

+107
-44
lines changed

10 files changed

+107
-44
lines changed

.rustfmt.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
max_width = 80
2+
wrap_comments = true
3+
reorder_imports = true
4+
edition = "2021"

examples/dump_mptcp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async fn get_addresses() {
2222
}
2323
assert!(!msgs.is_empty());
2424
for msg in msgs {
25-
println!("{:?}", msg);
25+
println!("{msg:?}");
2626
}
2727

2828
let mut limits_handle = handle.limits().get().execute().await;
@@ -33,6 +33,6 @@ async fn get_addresses() {
3333
}
3434
assert!(!msgs.is_empty());
3535
for msg in msgs {
36-
println!("{:?}", msg);
36+
println!("{msg:?}");
3737
}
3838
}

src/address/attr.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,21 @@ fn u32_to_vec_flags(value: u32) -> Vec<MptcpPathManagerAddressAttrFlag> {
6666
impl From<&MptcpPathManagerAddressAttrFlag> for u32 {
6767
fn from(v: &MptcpPathManagerAddressAttrFlag) -> u32 {
6868
match v {
69-
MptcpPathManagerAddressAttrFlag::Signal => MPTCP_PM_ADDR_FLAG_SIGNAL,
70-
MptcpPathManagerAddressAttrFlag::Subflow => MPTCP_PM_ADDR_FLAG_SUBFLOW,
71-
MptcpPathManagerAddressAttrFlag::Backup => MPTCP_PM_ADDR_FLAG_BACKUP,
72-
MptcpPathManagerAddressAttrFlag::Fullmesh => MPTCP_PM_ADDR_FLAG_FULLMESH,
73-
MptcpPathManagerAddressAttrFlag::Implicit => MPTCP_PM_ADDR_FLAG_IMPLICIT,
69+
MptcpPathManagerAddressAttrFlag::Signal => {
70+
MPTCP_PM_ADDR_FLAG_SIGNAL
71+
}
72+
MptcpPathManagerAddressAttrFlag::Subflow => {
73+
MPTCP_PM_ADDR_FLAG_SUBFLOW
74+
}
75+
MptcpPathManagerAddressAttrFlag::Backup => {
76+
MPTCP_PM_ADDR_FLAG_BACKUP
77+
}
78+
MptcpPathManagerAddressAttrFlag::Fullmesh => {
79+
MPTCP_PM_ADDR_FLAG_FULLMESH
80+
}
81+
MptcpPathManagerAddressAttrFlag::Implicit => {
82+
MPTCP_PM_ADDR_FLAG_IMPLICIT
83+
}
7484
MptcpPathManagerAddressAttrFlag::Other(d) => *d,
7585
}
7686
}
@@ -114,7 +124,9 @@ impl Nla for MptcpPathManagerAddressAttr {
114124

115125
fn emit_value(&self, buffer: &mut [u8]) {
116126
match self {
117-
Self::Family(d) | Self::Port(d) => NativeEndian::write_u16(buffer, *d),
127+
Self::Family(d) | Self::Port(d) => {
128+
NativeEndian::write_u16(buffer, *d)
129+
}
118130
Self::Addr4(i) => buffer.copy_from_slice(&i.octets()),
119131
Self::Addr6(i) => buffer.copy_from_slice(&i.octets()),
120132
Self::Id(d) => buffer[0] = *d,
@@ -131,12 +143,14 @@ impl Nla for MptcpPathManagerAddressAttr {
131143
}
132144
}
133145

134-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for MptcpPathManagerAddressAttr {
146+
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
147+
for MptcpPathManagerAddressAttr
148+
{
135149
fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
136150
let payload = buf.value();
137151
Ok(match buf.kind() {
138152
MPTCP_PM_ADDR_ATTR_FAMILY => {
139-
let err_msg = format!("Invalid MPTCP_PM_ADDR_ATTR_FAMILY value {:?}", payload);
153+
let err_msg = format!("Invalid MPTCP_PM_ADDR_ATTR_FAMILY value {payload:?}");
140154
Self::Family(parse_u16(payload).context(err_msg)?)
141155
}
142156
MPTCP_PM_ADDR_ATTR_ID => {

src/address/get.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use futures::TryStream;
44
use netlink_packet_generic::GenlMessage;
55

66
use crate::{
7-
mptcp_execute, MptcpPathManagerError, MptcpPathManagerHandle, MptcpPathManagerMessage,
7+
mptcp_execute, MptcpPathManagerError, MptcpPathManagerHandle,
8+
MptcpPathManagerMessage,
89
};
910

1011
pub struct MptcpPathManagerAddressGetRequest {
@@ -18,8 +19,10 @@ impl MptcpPathManagerAddressGetRequest {
1819

1920
pub async fn execute(
2021
self,
21-
) -> impl TryStream<Ok = GenlMessage<MptcpPathManagerMessage>, Error = MptcpPathManagerError>
22-
{
22+
) -> impl TryStream<
23+
Ok = GenlMessage<MptcpPathManagerMessage>,
24+
Error = MptcpPathManagerError,
25+
> {
2326
let MptcpPathManagerAddressGetRequest { mut handle } = self;
2427

2528
let mptcp_msg = MptcpPathManagerMessage::new_address_get();

src/handle.rs

+24-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use netlink_packet_generic::GenlMessage;
77
use netlink_packet_utils::DecodeError;
88

99
use crate::{
10-
try_mptcp, MptcpPathManagerAddressHandle, MptcpPathManagerCmd, MptcpPathManagerError,
11-
MptcpPathManagerLimitsHandle, MptcpPathManagerMessage,
10+
try_mptcp, MptcpPathManagerAddressHandle, MptcpPathManagerCmd,
11+
MptcpPathManagerError, MptcpPathManagerLimitsHandle,
12+
MptcpPathManagerMessage,
1213
};
1314

1415
#[derive(Clone, Debug)]
@@ -37,19 +38,29 @@ impl MptcpPathManagerHandle {
3738
&mut self,
3839
message: NetlinkMessage<GenlMessage<MptcpPathManagerMessage>>,
3940
) -> Result<
40-
impl Stream<Item = Result<NetlinkMessage<GenlMessage<MptcpPathManagerMessage>>, DecodeError>>,
41+
impl Stream<
42+
Item = Result<
43+
NetlinkMessage<GenlMessage<MptcpPathManagerMessage>>,
44+
DecodeError,
45+
>,
46+
>,
4147
MptcpPathManagerError,
4248
> {
4349
self.handle.request(message).await.map_err(|e| {
44-
MptcpPathManagerError::RequestFailed(format!("BUG: Request failed with {}", e))
50+
MptcpPathManagerError::RequestFailed(format!(
51+
"BUG: Request failed with {e}"
52+
))
4553
})
4654
}
4755
}
4856

4957
pub(crate) async fn mptcp_execute(
5058
handle: &mut MptcpPathManagerHandle,
5159
mptcp_msg: MptcpPathManagerMessage,
52-
) -> impl TryStream<Ok = GenlMessage<MptcpPathManagerMessage>, Error = MptcpPathManagerError> {
60+
) -> impl TryStream<
61+
Ok = GenlMessage<MptcpPathManagerMessage>,
62+
Error = MptcpPathManagerError,
63+
> {
5364
let nl_header_flags = match mptcp_msg.cmd {
5465
MptcpPathManagerCmd::AddressGet => NLM_F_REQUEST | NLM_F_DUMP,
5566
MptcpPathManagerCmd::LimitsGet => NLM_F_REQUEST,
@@ -60,10 +71,15 @@ pub(crate) async fn mptcp_execute(
6071
nl_msg.header.flags = nl_header_flags;
6172

6273
match handle.request(nl_msg).await {
63-
Ok(response) => Either::Left(response.map(move |msg| Ok(try_mptcp!(msg)))),
74+
Ok(response) => {
75+
Either::Left(response.map(move |msg| Ok(try_mptcp!(msg))))
76+
}
6477
Err(e) => Either::Right(
65-
futures::future::err::<GenlMessage<MptcpPathManagerMessage>, MptcpPathManagerError>(e)
66-
.into_stream(),
78+
futures::future::err::<
79+
GenlMessage<MptcpPathManagerMessage>,
80+
MptcpPathManagerError,
81+
>(e)
82+
.into_stream(),
6783
),
6884
}
6985
}

src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ pub use connection::new_connection_with_socket;
1818
pub use error::MptcpPathManagerError;
1919
pub use handle::MptcpPathManagerHandle;
2020
pub use limits::{
21-
MptcpPathManagerLimitsAttr, MptcpPathManagerLimitsGetRequest, MptcpPathManagerLimitsHandle,
21+
MptcpPathManagerLimitsAttr, MptcpPathManagerLimitsGetRequest,
22+
MptcpPathManagerLimitsHandle,
23+
};
24+
pub use message::{
25+
MptcpPathManagerAttr, MptcpPathManagerCmd, MptcpPathManagerMessage,
2226
};
23-
pub use message::{MptcpPathManagerAttr, MptcpPathManagerCmd, MptcpPathManagerMessage};
2427

2528
pub(crate) use handle::mptcp_execute;

src/limits/attr.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,31 @@ impl Nla for MptcpPathManagerLimitsAttr {
3636

3737
fn emit_value(&self, buffer: &mut [u8]) {
3838
match self {
39-
Self::RcvAddAddrs(d) | Self::Subflows(d) => NativeEndian::write_u32(buffer, *d),
39+
Self::RcvAddAddrs(d) | Self::Subflows(d) => {
40+
NativeEndian::write_u32(buffer, *d)
41+
}
4042
Self::Other(ref attr) => attr.emit(buffer),
4143
}
4244
}
4345
}
4446

45-
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for MptcpPathManagerLimitsAttr {
47+
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
48+
for MptcpPathManagerLimitsAttr
49+
{
4650
fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
4751
let payload = buf.value();
4852
Ok(match buf.kind() {
4953
MPTCP_PM_ATTR_RCV_ADD_ADDRS => Self::RcvAddAddrs(
50-
parse_u32(payload).context("Invalid MPTCP_PM_ATTR_RCV_ADD_ADDRS value")?,
54+
parse_u32(payload)
55+
.context("Invalid MPTCP_PM_ATTR_RCV_ADD_ADDRS value")?,
56+
),
57+
MPTCP_PM_ATTR_SUBFLOWS => Self::Subflows(
58+
parse_u32(payload)
59+
.context("Invalid MPTCP_PM_ATTR_SUBFLOWS value")?,
60+
),
61+
_ => Self::Other(
62+
DefaultNla::parse(buf).context("invalid NLA (unknown kind)")?,
5163
),
52-
MPTCP_PM_ATTR_SUBFLOWS => {
53-
Self::Subflows(parse_u32(payload).context("Invalid MPTCP_PM_ATTR_SUBFLOWS value")?)
54-
}
55-
_ => Self::Other(DefaultNla::parse(buf).context("invalid NLA (unknown kind)")?),
5664
})
5765
}
5866
}

src/limits/get.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use futures::TryStream;
44
use netlink_packet_generic::GenlMessage;
55

66
use crate::{
7-
mptcp_execute, MptcpPathManagerError, MptcpPathManagerHandle, MptcpPathManagerMessage,
7+
mptcp_execute, MptcpPathManagerError, MptcpPathManagerHandle,
8+
MptcpPathManagerMessage,
89
};
910

1011
pub struct MptcpPathManagerLimitsGetRequest {
@@ -18,8 +19,10 @@ impl MptcpPathManagerLimitsGetRequest {
1819

1920
pub async fn execute(
2021
self,
21-
) -> impl TryStream<Ok = GenlMessage<MptcpPathManagerMessage>, Error = MptcpPathManagerError>
22-
{
22+
) -> impl TryStream<
23+
Ok = GenlMessage<MptcpPathManagerMessage>,
24+
Error = MptcpPathManagerError,
25+
> {
2326
let MptcpPathManagerLimitsGetRequest { mut handle } = self;
2427

2528
let mptcp_msg = MptcpPathManagerMessage::new_limits_get();

src/message.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use netlink_packet_utils::{
77
DecodeError, Emitable, Parseable, ParseableParametrized,
88
};
99

10-
use crate::{address::MptcpPathManagerAddressAttr, limits::MptcpPathManagerLimitsAttr};
10+
use crate::{
11+
address::MptcpPathManagerAddressAttr, limits::MptcpPathManagerLimitsAttr,
12+
};
1113

1214
const MPTCP_PM_CMD_GET_ADDR: u8 = 3;
1315
const MPTCP_PM_CMD_GET_LIMITS: u8 = 6;
@@ -113,12 +115,15 @@ impl Emitable for MptcpPathManagerMessage {
113115
fn parse_nlas(buffer: &[u8]) -> Result<Vec<MptcpPathManagerAttr>, DecodeError> {
114116
let mut nlas = Vec::new();
115117
for nla in NlasIterator::new(buffer) {
116-
let error_msg = format!("Failed to parse mptcp address message attribute {:?}", nla);
118+
let error_msg =
119+
format!("Failed to parse mptcp address message attribute {nla:?}");
117120
let nla = &nla.context(error_msg)?;
118121
match nla.kind() {
119122
MPTCP_PM_ATTR_ADDR => {
120123
for addr_nla in NlasIterator::new(nla.value()) {
121-
let error_msg = format!("Failed to parse MPTCP_PM_ATTR_ADDR {:?}", addr_nla);
124+
let error_msg = format!(
125+
"Failed to parse MPTCP_PM_ATTR_ADDR {addr_nla:?}"
126+
);
122127
let addr_nla = &addr_nla.context(error_msg)?;
123128

124129
nlas.push(MptcpPathManagerAttr::Address(
@@ -127,10 +132,13 @@ fn parse_nlas(buffer: &[u8]) -> Result<Vec<MptcpPathManagerAttr>, DecodeError> {
127132
))
128133
}
129134
}
130-
MPTCP_PM_ATTR_RCV_ADD_ADDRS => nlas.push(MptcpPathManagerAttr::Limits(
131-
MptcpPathManagerLimitsAttr::parse(nla)
132-
.context("Failed to parse MPTCP_PM_ATTR_RCV_ADD_ADDRS")?,
133-
)),
135+
MPTCP_PM_ATTR_RCV_ADD_ADDRS => {
136+
nlas.push(MptcpPathManagerAttr::Limits(
137+
MptcpPathManagerLimitsAttr::parse(nla).context(
138+
"Failed to parse MPTCP_PM_ATTR_RCV_ADD_ADDRS",
139+
)?,
140+
))
141+
}
134142
MPTCP_PM_ATTR_SUBFLOWS => nlas.push(MptcpPathManagerAttr::Limits(
135143
MptcpPathManagerLimitsAttr::parse(nla)
136144
.context("Failed to parse MPTCP_PM_ATTR_RCV_ADD_ADDRS")?,
@@ -144,7 +152,10 @@ fn parse_nlas(buffer: &[u8]) -> Result<Vec<MptcpPathManagerAttr>, DecodeError> {
144152
}
145153

146154
impl ParseableParametrized<[u8], GenlHeader> for MptcpPathManagerMessage {
147-
fn parse_with_param(buffer: &[u8], header: GenlHeader) -> Result<Self, DecodeError> {
155+
fn parse_with_param(
156+
buffer: &[u8],
157+
header: GenlHeader,
158+
) -> Result<Self, DecodeError> {
148159
Ok(match header.cmd {
149160
MPTCP_PM_CMD_GET_ADDR => Self {
150161
cmd: MptcpPathManagerCmd::AddressGet,
@@ -156,8 +167,7 @@ impl ParseableParametrized<[u8], GenlHeader> for MptcpPathManagerMessage {
156167
},
157168
cmd => {
158169
return Err(DecodeError::from(format!(
159-
"Unsupported mptcp reply command: {}",
160-
cmd
170+
"Unsupported mptcp reply command: {cmd}"
161171
)))
162172
}
163173
})

tests/dump_mptcp.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ async fn assert_empty_addresses_and_limits() {
5959
let mptcp_nlas = &msgs[0].payload.nlas;
6060
assert_eq!(
6161
mptcp_nlas[0],
62-
MptcpPathManagerAttr::Limits(MptcpPathManagerLimitsAttr::RcvAddAddrs(0))
62+
MptcpPathManagerAttr::Limits(MptcpPathManagerLimitsAttr::RcvAddAddrs(
63+
0
64+
))
6365
);
6466
assert_eq!(
6567
mptcp_nlas[1],

0 commit comments

Comments
 (0)