7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1 | // Copyright 2025 The Matrix.org Foundation C.I.C. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 4 | // you may not use this file except in compliance with the License. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 5 | // You may obtain a copy of the License at |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 6 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 8 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 9 | // Unless required by applicable law or agreed to in writing, software |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 12 | // See the License for the specific language governing permissions and |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 13 | // limitations under the License. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 14 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 15 | //! Platform-specific stream utilities. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 16 | //! |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 17 | //! This module provides a unified `BoxStream` + `StreamExt` class for working |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 18 | //! with boxed streams across different platforms. On native platforms, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 19 | //! streams can be `Send`, but on Wasm they cannot. This module abstracts |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 20 | //! over that difference. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 21 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 22 | #[cfg(not(target_family = "wasm"))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 23 | mod sys { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 24 | // On native platforms, just re-export everything from futures_util |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 25 | pub use futures_util::{StreamExt, stream::BoxStream}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 26 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 27 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 28 | #[cfg(target_family = "wasm")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 29 | mod sys { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 30 | use futures_core::Stream; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 31 | // On Wasm, BoxStream is LocalBoxStream |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 32 | pub use futures_util::stream::LocalBoxStream as BoxStream; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 33 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 34 | /// Custom `StreamExt` trait for Wasm that provides essential methods |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 35 | /// like `.boxed()` and `.next()` without `Send` requirements. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 36 | pub trait StreamExt: Stream { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 37 | /// Box this stream using `LocalBoxStream` (no `Send` requirement). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 38 | fn boxed<'a>(self) -> BoxStream<'a, Self::Item> |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 39 | where |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 40 | Self: Sized + 'a, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 41 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 42 | futures_util::StreamExt::boxed_local(self) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 43 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 44 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 45 | /// Get the next item from this stream. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 46 | fn next(&mut self) -> futures_util::stream::Next<'_, Self> |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 47 | where |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 48 | Self: Unpin, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 49 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 50 | futures_util::StreamExt::next(self) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 51 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 52 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 53 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 54 | impl<S: Stream> StreamExt for S {} |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 55 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 56 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 57 | pub use sys::*; |