Skip to content

Commit ef8379e

Browse files
authored
Fix travis build (#65)
* Changed `assert_eq!` tests to `assert!` to fix the build. * Added semicolons to last line of functions to make pedantic clippy happy. * Changed explicit impl of Default for timetoken.rs to be derived instead. * Refactored assertion in subscription.rs to make clippy happy. * Allowing unknown lints so that the build can pass. Older versions use `broken_intra_doc_links` and newer ones use `rustdoc::broken_intra_doc_links`, so the build fails on one or the other, so allowing unknown lints for now. * Formatting to make the linter happy. * Allowing unused async, because it's required for `ControlOutcome`, but Clippy insists it isn't. * Resolving issues detected by Clippy: "expression borrows a reference...that is immediately dereferenced by the compiler" * Bumping minimum version to Rust 1.49.0 due to: - rust-lang/rust#55002 - rust-lang/rust#70921 * Added TODOs to remove linter allows for unknown, renamed, and removed lints when Rust 1.59.0 becomes minimum version. * Added todo where the default UUID behavior is specified.
1 parent 859c4b0 commit ef8379e

File tree

21 files changed

+88
-75
lines changed

21 files changed

+88
-75
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: rust
22
rust:
3-
- 1.46.0
3+
- 1.49.0
44
- stable
55
- beta
66
- nightly

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The PubNub Rust SDK is based on Tokio `1.0`. This library uses `HTTP/2` to commu
77

88
## MSRV
99

10-
Supports Rust 1.46.0 and higher.
10+
Supports Rust 1.49.0 and higher.
1111

1212
## Get Started
1313

pubnub-core/src/data/channel/name.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -80,35 +80,35 @@ mod tests {
8080
#[test]
8181
fn valid() {
8282
// Spec.
83-
assert_eq!(is_valid(""), true);
84-
assert_eq!(is_valid("qwe"), true);
85-
assert_eq!(is_valid("123"), true);
83+
assert!(is_valid(""));
84+
assert!(is_valid("qwe"));
85+
assert!(is_valid("123"));
8686
}
8787

8888
#[test]
8989
fn valid_but_not_officially() {
9090
// Spec.
91-
assert_eq!(is_valid("/"), true);
92-
assert_eq!(is_valid("\\"), true);
93-
assert_eq!(is_valid("."), true);
94-
assert_eq!(is_valid("*"), true);
95-
assert_eq!(is_valid(":"), true);
91+
assert!(is_valid("/"));
92+
assert!(is_valid("\\"));
93+
assert!(is_valid("."));
94+
assert!(is_valid("*"));
95+
assert!(is_valid(":"));
9696

9797
// Real world examples.
98-
assert_eq!(is_valid("a.b"), true);
99-
assert_eq!(is_valid("a:b"), true);
100-
assert_eq!(is_valid("a/b"), true);
101-
assert_eq!(is_valid("\\a"), true);
102-
assert_eq!(is_valid("channels_.*"), true);
103-
assert_eq!(is_valid("channels_*"), true);
98+
assert!(is_valid("a.b"));
99+
assert!(is_valid("a:b"));
100+
assert!(is_valid("a/b"));
101+
assert!(is_valid("\\a"));
102+
assert!(is_valid("channels_.*"));
103+
assert!(is_valid("channels_*"));
104104
}
105105

106106
#[test]
107107
fn invalid() {
108108
// Spec.
109-
assert_eq!(is_valid(","), false);
109+
assert!(!is_valid(","));
110110

111111
// Real world examples.
112-
assert_eq!(is_valid("a,b"), false);
112+
assert!(!is_valid("a,b"));
113113
}
114114
}

pubnub-core/src/data/channel/wildcard_spec.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,18 @@ mod tests {
130130

131131
#[test]
132132
fn valid() {
133-
assert_eq!(is_valid("stocks.*"), true); // from https://support.pubnub.com/support/solutions/articles/14000043663-how-do-i-subscribe-to-a-wildcard-channel-
134-
assert_eq!(is_valid(""), true);
133+
assert!(is_valid("stocks.*")); // from https://support.pubnub.com/support/solutions/articles/14000043663-how-do-i-subscribe-to-a-wildcard-channel-
134+
assert!(is_valid(""));
135135
}
136136

137137
#[test]
138138
fn valid_from_docs() {
139139
// From https://support.pubnub.com/support/solutions/articles/14000043664-how-many-channel-segments-are-supported-with-wildcard-subscribe-
140140

141-
assert_eq!(is_valid("a.*"), true);
142-
assert_eq!(is_valid("a.b.*"), true);
143-
assert_eq!(is_valid("a.b"), true);
144-
assert_eq!(is_valid("a.b.c"), true);
141+
assert!(is_valid("a.*"));
142+
assert!(is_valid("a.b.*"));
143+
assert!(is_valid("a.b"));
144+
assert!(is_valid("a.b.c"));
145145

146146
// Technically speaking, the last two examples are just single channels
147147
// without any wildcards, but you can subscribe to any of the above
@@ -152,12 +152,12 @@ mod tests {
152152
fn invalid_incorrect_from_docs() {
153153
// From https://support.pubnub.com/support/solutions/articles/14000043664-how-many-channel-segments-are-supported-with-wildcard-subscribe-
154154

155-
assert_eq!(is_valid("*"), false); // can not wildcard at the top level to subscribe to all channels
156-
assert_eq!(is_valid(".*"), false); // can not start with a .
157-
assert_eq!(is_valid("a.*.b"), false); // * must be at the end
158-
assert_eq!(is_valid("a."), false); // the . must be followed by a * when it is at the end of the name
159-
assert_eq!(is_valid("a*"), false); // * must always be preceded with a .
160-
assert_eq!(is_valid("a*b"), false); // * must always be preceded with a . and .* must always be at the end
155+
assert!(!is_valid("*")); // can not wildcard at the top level to subscribe to all channels
156+
assert!(!is_valid(".*")); // can not start with a .
157+
assert!(!is_valid("a.*.b")); // * must be at the end
158+
assert!(!is_valid("a.")); // the . must be followed by a * when it is at the end of the name
159+
assert!(!is_valid("a*")); // * must always be preceded with a .
160+
assert!(!is_valid("a*b")); // * must always be preceded with a . and .* must always be at the end
161161

162162
// NOTE: The above invalid channel names will actually succeed if you
163163
// attempt to subscribe to them. They will even succeed when you publish
@@ -182,8 +182,8 @@ mod tests {
182182
// two . characters (more than three segments) it will succeed, but
183183
// you will not be able to publish to those channels.
184184

185-
assert_eq!(is_valid("a.b.c.d"), false); // too many segments
186-
assert_eq!(is_valid("a.b.c.*"), false); // too many segments
185+
assert!(!is_valid("a.b.c.d")); // too many segments
186+
assert!(!is_valid("a.b.c.*")); // too many segments
187187

188188
// If you do attempt to publish to channel names with more than three
189189
// segments (three or more . delimiters), then you will receive a 400

pubnub-core/src/data/timetoken.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::time::{SystemTime, SystemTimeError};
77
/// This is the timetoken structure that PubNub uses as a stream index.
88
/// It allows clients to resume streaming from where they left off for added
99
/// resiliency.
10-
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
10+
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy, Default)]
1111
pub struct Timetoken {
1212
/// Timetoken
1313
pub t: u64,
@@ -57,16 +57,6 @@ impl Timetoken {
5757
}
5858
}
5959

60-
impl Default for Timetoken {
61-
#[must_use]
62-
fn default() -> Self {
63-
Self {
64-
t: u64::default(),
65-
r: u32::default(),
66-
}
67-
}
68-
}
69-
7060
impl std::fmt::Display for Timetoken {
7161
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
7262
write!(fmt, "{{ t: {}, r: {} }}", self.t, self.r)

pubnub-core/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
//!
1010
//! Build your own client, or use preconfigured [`pubnub-hyper`](pubnub-hyper).
1111
12+
// TODO: Remove these when minimum Rust version >1.59.0, when the name changed.
13+
// TODO: `broken_intra_doc_links` below should become `rustdoc::broken_intra_doc_links`.
14+
#![allow(unknown_lints)]
15+
#![allow(renamed_and_removed_lints)]
1216
#![deny(
1317
clippy::all,
1418
clippy::pedantic,

pubnub-core/src/mock/runtime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ impl Runtime for MockRuntime {
2929
where
3030
F: Future<Output = ()> + Send + 'static,
3131
{
32-
self.mock_workaround_spawn(Box::pin(future))
32+
self.mock_workaround_spawn(Box::pin(future));
3333
}
3434
}

pubnub-core/src/pubnub/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn mocked_pubnub_publish_ok() {
4848
.expect("unexpected failure");
4949
assert_eq!(timetoken.t, 123);
5050
assert_eq!(timetoken.r, 456);
51-
})
51+
});
5252
}
5353

5454
#[test]
@@ -185,7 +185,7 @@ fn mocked_pubnub_subscribe_ok() {
185185
})
186186
.unwrap();
187187

188-
pool.run()
188+
pool.run();
189189
}
190190

191191
#[allow(clippy::too_many_lines)]
@@ -333,5 +333,5 @@ fn mocked_pubnub_subscribe_trasport_error_does_not_stall_loop() {
333333
})
334334
.unwrap();
335335

336-
pool.run()
336+
pool.run();
337337
}

pubnub-core/src/subscription/message_destinations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ mod tests {
7575
}
7676

7777
fn assert_iter_eq(m: &Message, expected: &[pubsub::SubscribeTo]) {
78-
let iter = MessageDestinations::new(&m);
78+
let iter = MessageDestinations::new(m);
7979
let vec: Vec<_> = iter.collect();
8080
assert_eq!(vec, expected);
8181
}

pubnub-core/src/subscription/subscribe_loop.rs

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ enum ControlOutcome {
161161
}
162162

163163
/// Handle a control command.
164+
#[allow(clippy::unused_async)]
164165
async fn handle_control_command(
165166
state_data: &mut StateData,
166167
msg: Option<ControlCommand>,

pubnub-core/src/subscription/subscription.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ use std::pin::Pin;
1616
/// [`PubNub::subscribe`]: crate::pubnub::PubNub::subscribe
1717
#[derive(Debug)]
1818
pub struct Subscription<TRuntime: Runtime> {
19-
pub(crate) runtime: TRuntime, // Runtime to use for managing resources
20-
pub(crate) destination: pubsub::SubscribeTo, // Subscription destination
21-
pub(crate) id: SubscriptionID, // Unique identifier for the listener
22-
pub(crate) control_tx: ControlTx, // For cleaning up resources at the subscribe loop when dropped
19+
pub(crate) runtime: TRuntime,
20+
// Runtime to use for managing resources
21+
pub(crate) destination: pubsub::SubscribeTo,
22+
// Subscription destination
23+
pub(crate) id: SubscriptionID,
24+
// Unique identifier for the listener
25+
pub(crate) control_tx: ControlTx,
26+
// For cleaning up resources at the subscribe loop when dropped
2327
pub(crate) channel_rx: ChannelRx, // Stream that produces messages
2428
}
2529

@@ -55,9 +59,10 @@ impl<TRuntime: Runtime> Drop for Subscription<TRuntime> {
5559
// See: https://boats.gitlab.io/blog/post/poll-drop/
5660
self.runtime.spawn(async move {
5761
let drop_send_result = control_tx.send(command).await;
58-
if is_drop_send_result_error(drop_send_result) {
59-
panic!("Unable to unsubscribe");
60-
}
62+
assert!(
63+
!is_drop_send_result_error(drop_send_result),
64+
"Unable to unsubscribe"
65+
);
6166
});
6267
}
6368
}

pubnub-hyper/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
//! # };
4040
//! ```
4141
42+
// TODO: Remove these when minimum Rust version >1.59.0, when the name changed.
43+
// TODO: `broken_intra_doc_links` below should become `rustdoc::broken_intra_doc_links`.
44+
#![allow(unknown_lints)]
45+
#![allow(renamed_and_removed_lints)]
4246
#![deny(
4347
clippy::all,
4448
clippy::pedantic,

pubnub-hyper/src/transport/hyper/history.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl TransportService<request::GetHistory> for Hyper {
5252
.set_optional_scalar("end", end)
5353
.set_optional_scalar("include_meta", include_metadata)
5454
.build();
55-
let url = build_uri(&self, &path_and_query)?;
55+
let url = build_uri(self, &path_and_query)?;
5656

5757
// Send network request.
5858
let response = self.http_client.get(url).await?;
@@ -85,7 +85,7 @@ impl TransportService<request::DeleteHistory> for Hyper {
8585
.set_optional_scalar("start", start)
8686
.set_optional_scalar("end", end)
8787
.build();
88-
let url = build_uri(&self, &path_and_query)?;
88+
let url = build_uri(self, &path_and_query)?;
8989

9090
// Prepare the request.
9191
let req = Request::builder()
@@ -122,7 +122,7 @@ impl TransportService<request::MessageCountsWithTimetoken> for Hyper {
122122
.set_list("channels", channels)
123123
.set_scalar("timetoken", timetoken)
124124
.build();
125-
let url = build_uri(&self, &path_and_query)?;
125+
let url = build_uri(self, &path_and_query)?;
126126

127127
// Send network request.
128128
let response = self.http_client.get(url).await?;
@@ -157,7 +157,7 @@ impl TransportService<request::MessageCountsWithChannelTimetokens> for Hyper {
157157
.set_list("channels", names)
158158
.set_list("channelsTimetoken", timetokens)
159159
.build();
160-
let url = build_uri(&self, &path_and_query)?;
160+
let url = build_uri(self, &path_and_query)?;
161161

162162
// Send network request.
163163
let response = self.http_client.get(url).await?;

pubnub-hyper/src/transport/hyper/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl HyperBuilder {
7474
.build::<_, Body>(https)
7575
}
7676

77+
// TODO: Remove random default UUID and require user to specify one. https://github.com/pubnub/rust/issues/66
7778
fn default_uuid() -> UUID {
7879
UUID::random()
7980
}

pubnub-hyper/src/transport/hyper/pam.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl TransportService<request::Grant> for Hyper {
4040
.set_scalar("signature", signature)
4141
.set_scalar("timestamp", timestamp.to_string())
4242
.build();
43-
let url = build_uri(&self, &path_and_query)?;
43+
let url = build_uri(self, &path_and_query)?;
4444

4545
// Prepare the request.
4646
let req = Request::builder()

pubnub-hyper/src/transport/hyper/presence.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl TransportService<request::SetState> for Hyper {
143143
.set_scalar("uuid", uuid)
144144
.set_scalar("state", json::stringify(state))
145145
.build();
146-
let url = build_uri(&self, &path_and_query)?;
146+
let url = build_uri(self, &path_and_query)?;
147147

148148
// Send network request.
149149
let response = self.http_client.get(url).await?;
@@ -174,7 +174,7 @@ impl TransportService<request::GetState> for Hyper {
174174
.set_list_with_if_empty("channel-group", channel_groups, IfEmpty::Skip)
175175
.set_scalar("uuid", uuid)
176176
.build();
177-
let url = build_uri(&self, &path_and_query)?;
177+
let url = build_uri(self, &path_and_query)?;
178178

179179
// Send network request.
180180
let response = self.http_client.get(url).await?;
@@ -208,7 +208,7 @@ impl TransportService<request::HereNow<presence::respond_with::OccupancyOnly>> f
208208
.set_list_with_if_empty("channel", channels, IfEmpty::Comma)
209209
.set_list_with_if_empty("channel-group", channel_groups, IfEmpty::Skip)
210210
.build();
211-
let url = build_uri(&self, &path_and_query)?;
211+
let url = build_uri(self, &path_and_query)?;
212212

213213
// Send network request.
214214
let response = self.http_client.get(url).await?;
@@ -244,7 +244,7 @@ impl TransportService<request::HereNow<presence::respond_with::OccupancyAndUUIDs
244244
.set_list_with_if_empty("channel", channels, IfEmpty::Comma)
245245
.set_list_with_if_empty("channel-group", channel_groups, IfEmpty::Skip)
246246
.build();
247-
let url = build_uri(&self, &path_and_query)?;
247+
let url = build_uri(self, &path_and_query)?;
248248

249249
// Send network request.
250250
let response = self.http_client.get(url).await?;
@@ -281,7 +281,7 @@ impl TransportService<request::HereNow<presence::respond_with::Full>> for Hyper
281281
.set_list_with_if_empty("channel", channels, IfEmpty::Comma)
282282
.set_list_with_if_empty("channel-group", channel_groups, IfEmpty::Skip)
283283
.build();
284-
let url = build_uri(&self, &path_and_query)?;
284+
let url = build_uri(self, &path_and_query)?;
285285

286286
// Send network request.
287287
let response = self.http_client.get(url).await?;
@@ -310,7 +310,7 @@ impl TransportService<request::GlobalHereNow<presence::respond_with::OccupancyOn
310310
UriTemplate::new("/v2/presence/sub-key/{sub_key}?disable_uuids=1&state=0")
311311
.set_scalar("sub_key", self.subscribe_key.clone())
312312
.build();
313-
let url = build_uri(&self, &path_and_query)?;
313+
let url = build_uri(self, &path_and_query)?;
314314

315315
// Send network request.
316316
let response = self.http_client.get(url).await?;
@@ -340,7 +340,7 @@ impl TransportService<request::GlobalHereNow<presence::respond_with::OccupancyAn
340340
UriTemplate::new("/v2/presence/sub-key/{sub_key}?disable_uuids=0&state=0")
341341
.set_scalar("sub_key", self.subscribe_key.clone())
342342
.build();
343-
let url = build_uri(&self, &path_and_query)?;
343+
let url = build_uri(self, &path_and_query)?;
344344

345345
// Send network request.
346346
let response = self.http_client.get(url).await?;
@@ -372,7 +372,7 @@ impl TransportService<request::GlobalHereNow<presence::respond_with::Full>> for
372372
UriTemplate::new("/v2/presence/sub-key/{sub_key}?disable_uuids=0&state=1")
373373
.set_scalar("sub_key", self.subscribe_key.clone())
374374
.build();
375-
let url = build_uri(&self, &path_and_query)?;
375+
let url = build_uri(self, &path_and_query)?;
376376

377377
// Send network request.
378378
let response = self.http_client.get(url).await?;
@@ -398,7 +398,7 @@ impl TransportService<request::WhereNow> for Hyper {
398398
.set_scalar("sub_key", self.subscribe_key.clone())
399399
.set_scalar("uuid", uuid)
400400
.build();
401-
let url = build_uri(&self, &path_and_query)?;
401+
let url = build_uri(self, &path_and_query)?;
402402

403403
// Send network request.
404404
let response = self.http_client.get(url).await?;
@@ -441,7 +441,7 @@ impl TransportService<request::Heartbeat> for Hyper {
441441
.set_optional_scalar("heartbeat", heartbeat.map(|e|e.to_string()))
442442
.set_scalar("state", json::stringify(state))
443443
.build();
444-
let url = build_uri(&self, &path_and_query)?;
444+
let url = build_uri(self, &path_and_query)?;
445445

446446
// Send network request.
447447
let response = self.http_client.get(url).await?;

0 commit comments

Comments
 (0)