Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Commit

Permalink
Migrate Rust Futures 0.2 → 0.3
Browse files Browse the repository at this point in the history
Relevant Rust RFC: <rust-lang/rfcs#2592>
  • Loading branch information
yvt committed Nov 17, 2018
1 parent 664967a commit a28b80f
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 163 deletions.
105 changes: 50 additions & 55 deletions EngineCore/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion EngineCore/src/ngsgamegfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
query_interface = "0.3.4"
futures-preview = "0.2.2"
futures-preview = "0.3.0-alpha.9"
pod = "0.5.0"
arrayvec = "0.4.1"
rand = "0.5.0"
Expand All @@ -16,7 +16,9 @@ parking_lot = "0.6"
owning_ref = "0.4.0"
opaque_typedef = "0.0.4"
opaque_typedef_macros = "0.0.4"
pin-utils = "0.1.0-alpha.3"
cryo = { version = "0.1.1", features = ["use_parking_lot"] }
either = { version = "1.4" }
zangfx = { path = "../zangfx" }
ngspf = { path = "../ngspf" }
ngsenumflags = { path = "../support/ngsenumflags" }
Expand Down
20 changes: 9 additions & 11 deletions EngineCore/src/ngsgamegfx/src/asyncuploader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use futures::{
use std::{
fmt,
ops::Range,
pin::Unpin,
sync::{Arc, Mutex},
thread,
};
Expand Down Expand Up @@ -112,7 +113,7 @@ pub struct AsyncUploader {

type ChannelPayload = Box<dyn FnOnce() -> StreamerRequestStream + Send + 'static>;

type StreamerRequestStream = Box<dyn Stream<Item = StreamerRequest, Error = Never>>;
type StreamerRequestStream = Box<dyn Stream<Item = StreamerRequest> + Unpin>;

#[derive(Debug)]
pub enum UploadError {
Expand Down Expand Up @@ -153,21 +154,18 @@ impl AsyncUploader {
cmd_generator.dst_queue_family = Some(dst_queue_family);
}

let streamer = streamer::Builder::default(device, queue)
let mut streamer = streamer::Builder::default(device, queue)
.with_cmd_generator(cmd_generator)
.with_batch_size(1024 * 1024 * 10)
.build_with_heap_size(1024 * 1024 * 100)?;

let request_stream = receiver
.map(|x: ChannelPayload| x())
.flatten()
.map_err(|_: Never| -> gfx::Error { unreachable!() });
let mut request_stream = receiver.map(|x: ChannelPayload| x()).flatten();

let result = streamer.send_all(request_stream);
let result = streamer.send_all(&mut request_stream);

let mut pool = executor::LocalPool::new();

pool.run_until(result, &mut pool.executor())
pool.run_until(result)
})() {
// Something went wrong in the uploader thread.
// Store the error reason before hanging up the receiver.
Expand Down Expand Up @@ -231,10 +229,10 @@ impl AsyncUploader {
pub fn upload<T, R>(
&self,
request_source: impl 'static + Send + Sync + FnOnce() -> T,
) -> impl Future<Item = (), Error = UploadError> + Send + Sync + 'static
) -> impl Future<Output = Result<(), UploadError>> + Send + Sync + 'static
where
T: Stream<Item = R, Error = Never> + 'static,
R: Request + 'static,
T: Stream<Item = R> + Unpin + 'static,
R: Request + Unpin + 'static,
{
// Use this channel to notify the completion
let (sender, receiver) = oneshot::channel();
Expand Down
3 changes: 3 additions & 0 deletions EngineCore/src/ngsgamegfx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
//
//! NgsGameGFX — Nightingales Game GFX
#![feature(unsized_locals)] // For calling boxed `FnOnce`
#![feature(futures_api)]
#![feature(pin)]
#![feature(arbitrary_self_types)]

mod asyncuploader;
mod cbtasks;
Expand Down

0 comments on commit a28b80f

Please sign in to comment.