Skip to content

Commit 046e038

Browse files
committed
Remove superfluous .to_vec()'s, and replace some with vec![]
1 parent 37db6de commit 046e038

File tree

1 file changed

+76
-116
lines changed

1 file changed

+76
-116
lines changed

talpid-wireguard/src/wireguard_kernel/wg_message.rs

+76-116
Original file line numberDiff line numberDiff line change
@@ -707,73 +707,54 @@ mod test {
707707

708708
let if_name = CString::new(b"wg-test".to_vec()).unwrap();
709709

710-
let peer_1 = PeerMessage(
711-
[
712-
PeerNla::PublicKey([
713-
32, 224, 68, 5, 23, 136, 103, 229, 206, 59, 34, 231, 215, 139, 214, 236, 80,
714-
81, 187, 7, 154, 197, 251, 36, 171, 156, 48, 73, 145, 47, 134, 54,
715-
]),
716-
PeerNla::PresharedKey([
717-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
718-
0, 0, 0, 0, 0, 0,
719-
]),
720-
LastHandshakeTime(TimeSpec::seconds(0)),
721-
PersistentKeepaliveInterval(0),
722-
TxBytes(0),
723-
RxBytes(0),
724-
ProtocolVersion(1),
725-
Endpoint(InetAddr::from_std(&"192.168.40.1:9797".parse().unwrap())),
726-
AllowedIps(
727-
[AllowedIpMessage(
728-
[
729-
CidrMask(32),
730-
AddressFamily(2),
731-
IpAddr(Ipv4Addr::new(192, 168, 39, 1).into()),
732-
]
733-
.to_vec(),
734-
)]
735-
.to_vec()
736-
.to_vec(),
737-
),
738-
]
739-
.to_vec(),
740-
);
741-
742-
let peer_2 = PeerMessage(
743-
[
744-
PeerNla::PublicKey([
745-
244, 28, 206, 12, 79, 36, 88, 183, 194, 157, 54, 38, 54, 183, 127, 32, 142, 24,
746-
251, 158, 217, 56, 12, 146, 208, 21, 132, 157, 162, 68, 2, 44,
747-
]),
748-
PresharedKey([
749-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
750-
0, 0, 0, 0, 0, 0,
751-
]),
752-
LastHandshakeTime(TimeSpec::seconds(0)),
753-
PersistentKeepaliveInterval(0),
754-
TxBytes(0),
755-
RxBytes(0),
756-
ProtocolVersion(1),
757-
Endpoint(InetAddr::from_std(&"192.168.40.2:9797".parse().unwrap())),
758-
AllowedIps(
759-
[AllowedIpMessage(
760-
[
761-
CidrMask(32),
762-
AddressFamily(2),
763-
IpAddr(Ipv4Addr::new(192, 168, 39, 2).into()),
764-
]
765-
.to_vec(),
766-
)]
767-
.to_vec(),
768-
),
769-
]
770-
.to_vec(),
771-
);
710+
let peer_1 = PeerMessage(vec![
711+
PeerNla::PublicKey([
712+
32, 224, 68, 5, 23, 136, 103, 229, 206, 59, 34, 231, 215, 139, 214, 236, 80, 81,
713+
187, 7, 154, 197, 251, 36, 171, 156, 48, 73, 145, 47, 134, 54,
714+
]),
715+
PeerNla::PresharedKey([
716+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
717+
0, 0, 0, 0,
718+
]),
719+
LastHandshakeTime(TimeSpec::seconds(0)),
720+
PersistentKeepaliveInterval(0),
721+
TxBytes(0),
722+
RxBytes(0),
723+
ProtocolVersion(1),
724+
Endpoint(InetAddr::from_std(&"192.168.40.1:9797".parse().unwrap())),
725+
AllowedIps(vec![AllowedIpMessage(vec![
726+
CidrMask(32),
727+
AddressFamily(2),
728+
IpAddr(Ipv4Addr::new(192, 168, 39, 1).into()),
729+
])]),
730+
]);
731+
732+
let peer_2 = PeerMessage(vec![
733+
PeerNla::PublicKey([
734+
244, 28, 206, 12, 79, 36, 88, 183, 194, 157, 54, 38, 54, 183, 127, 32, 142, 24,
735+
251, 158, 217, 56, 12, 146, 208, 21, 132, 157, 162, 68, 2, 44,
736+
]),
737+
PresharedKey([
738+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
739+
0, 0, 0, 0,
740+
]),
741+
LastHandshakeTime(TimeSpec::seconds(0)),
742+
PersistentKeepaliveInterval(0),
743+
TxBytes(0),
744+
RxBytes(0),
745+
ProtocolVersion(1),
746+
Endpoint(InetAddr::from_std(&"192.168.40.2:9797".parse().unwrap())),
747+
AllowedIps(vec![AllowedIpMessage(vec![
748+
CidrMask(32),
749+
AddressFamily(2),
750+
IpAddr(Ipv4Addr::new(192, 168, 39, 2).into()),
751+
])]),
752+
]);
772753

773754
DeviceMessage {
774755
command: WG_CMD_GET_DEVICE,
775756
message_type: 0,
776-
nlas: [
757+
nlas: vec![
777758
ListenPort(51820),
778759
Fwmark(0),
779760
IfIndex(320),
@@ -786,9 +767,8 @@ mod test {
786767
102, 218, 178, 222, 191, 21, 59, 83, 124, 180, 124, 41, 91, 10, 134, 199, 84,
787768
186, 27, 218, 53, 216, 20, 93, 203, 82, 68, 74, 189, 142, 99, 59,
788769
]),
789-
Peers([peer_1, peer_2].to_vec()),
790-
]
791-
.to_vec(),
770+
Peers(vec![peer_1, peer_2]),
771+
],
792772
}
793773
}
794774

@@ -799,66 +779,46 @@ mod test {
799779

800780
let if_name = CString::new("wg-test".to_string()).unwrap();
801781

802-
let peer_1 = PeerMessage(
803-
[
804-
PeerNla::PublicKey([
805-
32, 224, 68, 5, 23, 136, 103, 229, 206, 59, 34, 231, 215, 139, 214, 236, 80,
806-
81, 187, 7, 154, 197, 251, 36, 171, 156, 48, 73, 145, 47, 134, 54,
807-
]),
808-
Endpoint(InetAddr::from_std(&"192.168.40.1:9797".parse().unwrap())),
809-
PeerNla::Flags(WGPEER_F_REPLACE_ALLOWEDIPS),
810-
AllowedIps(
811-
[AllowedIpMessage(
812-
[
813-
AddressFamily(2),
814-
IpAddr(Ipv4Addr::new(192, 168, 39, 1).into()),
815-
CidrMask(32),
816-
]
817-
.to_vec(),
818-
)]
819-
.to_vec()
820-
.to_vec(),
821-
),
822-
]
823-
.to_vec(),
824-
);
825-
826-
let peer_2 = PeerMessage(
827-
[
828-
PeerNla::PublicKey([
829-
244, 28, 206, 12, 79, 36, 88, 183, 194, 157, 54, 38, 54, 183, 127, 32, 142, 24,
830-
251, 158, 217, 56, 12, 146, 208, 21, 132, 157, 162, 68, 2, 44,
831-
]),
832-
Endpoint(InetAddr::from_std(&"192.168.40.2:9797".parse().unwrap())),
833-
PeerNla::Flags(WGPEER_F_REPLACE_ALLOWEDIPS),
834-
AllowedIps(
835-
[AllowedIpMessage(
836-
[
837-
AddressFamily(2),
838-
IpAddr(Ipv4Addr::new(192, 168, 39, 2).into()),
839-
CidrMask(32),
840-
]
841-
.to_vec(),
842-
)]
843-
.to_vec(),
844-
),
845-
]
846-
.to_vec(),
847-
);
782+
let peer_1 = PeerMessage(vec![
783+
PeerNla::PublicKey([
784+
32, 224, 68, 5, 23, 136, 103, 229, 206, 59, 34, 231, 215, 139, 214, 236, 80, 81,
785+
187, 7, 154, 197, 251, 36, 171, 156, 48, 73, 145, 47, 134, 54,
786+
]),
787+
Endpoint(InetAddr::from_std(&"192.168.40.1:9797".parse().unwrap())),
788+
PeerNla::Flags(WGPEER_F_REPLACE_ALLOWEDIPS),
789+
AllowedIps(vec![AllowedIpMessage(vec![
790+
AddressFamily(2),
791+
IpAddr(Ipv4Addr::new(192, 168, 39, 1).into()),
792+
CidrMask(32),
793+
])]),
794+
]);
795+
796+
let peer_2 = PeerMessage(vec![
797+
PeerNla::PublicKey([
798+
244, 28, 206, 12, 79, 36, 88, 183, 194, 157, 54, 38, 54, 183, 127, 32, 142, 24,
799+
251, 158, 217, 56, 12, 146, 208, 21, 132, 157, 162, 68, 2, 44,
800+
]),
801+
Endpoint(InetAddr::from_std(&"192.168.40.2:9797".parse().unwrap())),
802+
PeerNla::Flags(WGPEER_F_REPLACE_ALLOWEDIPS),
803+
AllowedIps(vec![AllowedIpMessage(vec![
804+
AddressFamily(2),
805+
IpAddr(Ipv4Addr::new(192, 168, 39, 2).into()),
806+
CidrMask(32),
807+
])]),
808+
]);
848809

849810
DeviceMessage {
850811
command: WG_CMD_SET_DEVICE,
851812
message_type: 0,
852-
nlas: [
813+
nlas: vec![
853814
IfName(if_name),
854815
PrivateKey([
855816
56, 71, 244, 173, 101, 223, 85, 22, 171, 175, 15, 39, 53, 180, 193, 198, 73,
856817
55, 53, 59, 188, 26, 52, 74, 173, 179, 22, 213, 161, 71, 252, 125,
857818
]),
858819
ListenPort(51820),
859-
Peers([peer_1, peer_2].to_vec()),
860-
]
861-
.to_vec(),
820+
Peers(vec![peer_1, peer_2]),
821+
],
862822
}
863823
}
864824

0 commit comments

Comments
 (0)