Skip to content

Commit

Permalink
Reformatted for futures
Browse files Browse the repository at this point in the history
  • Loading branch information
Jujstme committed Feb 2, 2024
1 parent 8e5ebca commit 3c217d3
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 29 deletions.
12 changes: 8 additions & 4 deletions src/emulator/gba/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,20 @@ pub struct UntilEmulatorCloses<'a, F> {
future: F,
}

impl<F: Future<Output = ()>> Future for UntilEmulatorCloses<'_, F> {
type Output = ();
impl<T, F: Future<Output = T>> Future for UntilEmulatorCloses<'_, F> {
type Output = Option<T>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if !self.emulator.is_open() {
return Poll::Ready(());
return Poll::Ready(None);
}
self.emulator.update();
// SAFETY: We are simply projecting the Pin.
unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().future).poll(cx) }
unsafe {
Pin::new_unchecked(&mut self.get_unchecked_mut().future)
.poll(cx)
.map(Some)
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/emulator/gcn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,20 @@ pub struct UntilEmulatorCloses<'a, F> {
future: F,
}

impl<F: Future<Output = ()>> Future for UntilEmulatorCloses<'_, F> {
type Output = ();
impl<T, F: Future<Output = T>> Future for UntilEmulatorCloses<'_, F> {
type Output = Option<T>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if !self.emulator.is_open() {
return Poll::Ready(());
return Poll::Ready(None);
}
self.emulator.update();
// SAFETY: We are simply projecting the Pin.
unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().future).poll(cx) }
unsafe {
Pin::new_unchecked(&mut self.get_unchecked_mut().future)
.poll(cx)
.map(Some)
}
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/emulator/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,20 @@ pub struct UntilEmulatorCloses<'a, F> {
future: F,
}

impl<F: Future<Output = ()>> Future for UntilEmulatorCloses<'_, F> {
type Output = ();
impl<T, F: Future<Output = T>> Future for UntilEmulatorCloses<'_, F> {
type Output = Option<T>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if !self.emulator.process.is_open() {
return Poll::Ready(());
if !self.emulator.is_open() {
return Poll::Ready(None);
}
self.emulator.update();
// SAFETY: We are simply projecting the Pin.
unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().future).poll(cx) }
unsafe {
Pin::new_unchecked(&mut self.get_unchecked_mut().future)
.poll(cx)
.map(Some)
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/emulator/ps1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,20 @@ pub struct UntilEmulatorCloses<'a, F> {
future: F,
}

impl<F: Future<Output = ()>> Future for UntilEmulatorCloses<'_, F> {
type Output = ();
impl<T, F: Future<Output = T>> Future for UntilEmulatorCloses<'_, F> {
type Output = Option<T>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if !self.emulator.is_open() {
return Poll::Ready(());
return Poll::Ready(None);
}
self.emulator.update();
// SAFETY: We are simply projecting the Pin.
unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().future).poll(cx) }
unsafe {
Pin::new_unchecked(&mut self.get_unchecked_mut().future)
.poll(cx)
.map(Some)
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/emulator/ps2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,20 @@ pub struct UntilEmulatorCloses<'a, F> {
future: F,
}

impl<F: Future<Output = ()>> Future for UntilEmulatorCloses<'_, F> {
type Output = ();
impl<T, F: Future<Output = T>> Future for UntilEmulatorCloses<'_, F> {
type Output = Option<T>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if !self.emulator.is_open() {
return Poll::Ready(());
return Poll::Ready(None);
}
self.emulator.update();
// SAFETY: We are simply projecting the Pin.
unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().future).poll(cx) }
unsafe {
Pin::new_unchecked(&mut self.get_unchecked_mut().future)
.poll(cx)
.map(Some)
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/emulator/sms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,20 @@ pub struct UntilEmulatorCloses<'a, F> {
future: F,
}

impl<F: Future<Output = ()>> Future for UntilEmulatorCloses<'_, F> {
type Output = ();
impl<T, F: Future<Output = T>> Future for UntilEmulatorCloses<'_, F> {
type Output = Option<T>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if !self.emulator.is_open() {
return Poll::Ready(());
return Poll::Ready(None);
}
self.emulator.update();
// SAFETY: We are simply projecting the Pin.
unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().future).poll(cx) }
unsafe {
Pin::new_unchecked(&mut self.get_unchecked_mut().future)
.poll(cx)
.map(Some)
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/emulator/wii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,20 @@ pub struct UntilEmulatorCloses<'a, F> {
future: F,
}

impl<F: Future<Output = ()>> Future for UntilEmulatorCloses<'_, F> {
type Output = ();
impl<T, F: Future<Output = T>> Future for UntilEmulatorCloses<'_, F> {
type Output = Option<T>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if !self.emulator.is_open() {
return Poll::Ready(());
return Poll::Ready(None);
}
self.emulator.update();
// SAFETY: We are simply projecting the Pin.
unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().future).poll(cx) }
unsafe {
Pin::new_unchecked(&mut self.get_unchecked_mut().future)
.poll(cx)
.map(Some)
}
}
}

Expand Down

0 comments on commit 3c217d3

Please sign in to comment.