Skip to content

Commit ad2e3a3

Browse files
zecakehpoljar
authored andcommitted
common: Put UpdatesSubscriber behind test cfg
Since it is only used in tests, it is now detected as dead code. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
1 parent 96119f9 commit ad2e3a3

File tree

1 file changed

+18
-13
lines changed
  • crates/matrix-sdk-common/src/linked_chunk

1 file changed

+18
-13
lines changed

crates/matrix-sdk-common/src/linked_chunk/updates.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414

1515
use std::{
1616
collections::HashMap,
17-
pin::Pin,
18-
sync::{Arc, RwLock, Weak},
19-
task::{Context, Poll, Waker},
17+
sync::{Arc, RwLock},
18+
task::Waker,
2019
};
2120

22-
use futures_core::Stream;
23-
2421
use super::{ChunkIdentifier, Position};
2522

2623
/// Represent the updates that have happened inside a [`LinkedChunk`].
@@ -321,36 +318,42 @@ impl<Item, Gap> UpdatesInner<Item, Gap> {
321318

322319
/// A subscriber to [`ObservableUpdates`]. It is helpful to receive updates via
323320
/// a [`Stream`].
321+
#[cfg(test)]
324322
pub(super) struct UpdatesSubscriber<Item, Gap> {
325323
/// Weak reference to [`UpdatesInner`].
326324
///
327325
/// Using a weak reference allows [`ObservableUpdates`] to be dropped
328326
/// freely even if a subscriber exists.
329-
updates: Weak<RwLock<UpdatesInner<Item, Gap>>>,
327+
updates: std::sync::Weak<RwLock<UpdatesInner<Item, Gap>>>,
330328

331329
/// The token to read the updates.
332330
token: ReaderToken,
333331
}
334332

333+
#[cfg(test)]
335334
impl<Item, Gap> UpdatesSubscriber<Item, Gap> {
336335
/// Create a new [`Self`].
337336
#[cfg(test)]
338-
fn new(updates: Weak<RwLock<UpdatesInner<Item, Gap>>>, token: ReaderToken) -> Self {
337+
fn new(updates: std::sync::Weak<RwLock<UpdatesInner<Item, Gap>>>, token: ReaderToken) -> Self {
339338
Self { updates, token }
340339
}
341340
}
342341

343-
impl<Item, Gap> Stream for UpdatesSubscriber<Item, Gap>
342+
#[cfg(test)]
343+
impl<Item, Gap> futures_core::Stream for UpdatesSubscriber<Item, Gap>
344344
where
345345
Item: Clone,
346346
Gap: Clone,
347347
{
348348
type Item = Vec<Update<Item, Gap>>;
349349

350-
fn poll_next(self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Option<Self::Item>> {
350+
fn poll_next(
351+
self: std::pin::Pin<&mut Self>,
352+
context: &mut std::task::Context<'_>,
353+
) -> std::task::Poll<Option<Self::Item>> {
351354
let Some(updates) = self.updates.upgrade() else {
352355
// The `ObservableUpdates` has been dropped. It's time to close this stream.
353-
return Poll::Ready(None);
356+
return std::task::Poll::Ready(None);
354357
};
355358

356359
let mut updates = updates.write().unwrap();
@@ -362,14 +365,15 @@ where
362365
updates.wakers.push(context.waker().clone());
363366

364367
// The stream is pending.
365-
return Poll::Pending;
368+
return std::task::Poll::Pending;
366369
}
367370

368371
// There is updates! Let's forward them in this stream.
369-
Poll::Ready(Some(the_updates.to_owned()))
372+
std::task::Poll::Ready(Some(the_updates.to_owned()))
370373
}
371374
}
372375

376+
#[cfg(test)]
373377
impl<Item, Gap> Drop for UpdatesSubscriber<Item, Gap> {
374378
fn drop(&mut self) {
375379
// Remove `Self::token` from `UpdatesInner::last_index_per_reader`.
@@ -394,9 +398,10 @@ mod tests {
394398
};
395399

396400
use assert_matches::assert_matches;
401+
use futures_core::Stream;
397402
use futures_util::pin_mut;
398403

399-
use super::{super::LinkedChunk, ChunkIdentifier, Position, Stream, UpdatesInner};
404+
use super::{super::LinkedChunk, ChunkIdentifier, Position, UpdatesInner};
400405

401406
#[test]
402407
fn test_updates_take_and_garbage_collector() {

0 commit comments

Comments
 (0)