Skip to content

Commit 62f2aff

Browse files
committed
Simplify async map API
1 parent bdc6179 commit 62f2aff

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

dunge/src/context.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ impl Context {
124124
CopyBuffer::new(&self.0, size)
125125
}
126126

127-
pub async fn map_view<'a, S, R, F>(&self, view: CopyBufferView<'a>, tx: S, rx: R) -> Mapped<'a>
127+
pub async fn map_view<'a, S, R>(&self, view: CopyBufferView<'a>, tx: S, rx: R) -> Mapped<'a>
128128
where
129129
S: FnOnce(MapResult) + wgpu::WasmNotSend + 'static,
130-
R: FnOnce() -> F,
131-
F: IntoFuture<Output = MapResult>,
130+
R: IntoFuture<Output = MapResult>,
132131
{
133132
view.map(&self.0, tx, rx).await
134133
}

dunge/src/texture.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,16 @@ pub type MapResult = Result<(), BufferAsyncError>;
305305
pub struct CopyBufferView<'a>(BufferSlice<'a>);
306306

307307
impl<'a> CopyBufferView<'a> {
308-
pub(crate) async fn map<S, R, F>(self, state: &State, tx: S, rx: R) -> Mapped<'a>
308+
pub(crate) async fn map<S, R>(self, state: &State, tx: S, rx: R) -> Mapped<'a>
309309
where
310310
S: FnOnce(MapResult) + WasmNotSend + 'static,
311-
R: FnOnce() -> F,
312-
F: IntoFuture<Output = MapResult>,
311+
R: IntoFuture<Output = MapResult>,
313312
{
314313
use wgpu::*;
315314

316315
self.0.map_async(MapMode::Read, tx);
317316
state.device().poll(Maintain::Wait);
318-
if let Err(err) = rx().await {
317+
if let Err(err) = rx.await {
319318
panic!("failed to copy texture: {err}");
320319
}
321320

helpers/src/channel.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{future::Future, pin::Pin};
22

33
type Sender<T> = Box<dyn FnOnce(T) + Send>;
4-
type Receiver<T> = Box<dyn FnOnce() -> Pin<Box<dyn Future<Output = T>>>>;
4+
type Receiver<T> = Pin<Box<dyn Future<Output = T>>>;
55

66
pub fn oneshot<T>() -> (Sender<T>, Receiver<T>)
77
where
@@ -10,6 +10,6 @@ where
1010
let (tx, rx) = async_channel::bounded(1);
1111
(
1212
Box::new(move |r| tx.send_blocking(r).expect("send mapped result")),
13-
Box::new(|| Box::pin(async move { rx.recv().await.expect("recv mapped result") })),
13+
Box::pin(async move { rx.recv().await.expect("recv mapped result") }),
1414
)
1515
}

0 commit comments

Comments
 (0)