From 5ee2b8742a53e93c5b6a7ca48a338096864c8d1f Mon Sep 17 00:00:00 2001 From: Peter Huene Date: Wed, 3 Mar 2021 13:27:56 -0800 Subject: [PATCH] Have `new_with_stack` impls return `io::Result`. --- crates/fiber/src/lib.rs | 2 +- crates/fiber/src/unix.rs | 4 ++-- crates/fiber/src/windows.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/fiber/src/lib.rs b/crates/fiber/src/lib.rs index 6c835c511f..9a8d057f35 100644 --- a/crates/fiber/src/lib.rs +++ b/crates/fiber/src/lib.rs @@ -66,7 +66,7 @@ impl<'a, Resume, Yield, Return> Fiber<'a, Resume, Yield, Return> { func: impl FnOnce(Resume, &Suspend) -> Return + 'a, ) -> io::Result> { Ok(Fiber { - inner: imp::Fiber::new_with_stack(top_of_stack, func), + inner: imp::Fiber::new_with_stack(top_of_stack, func)?, done: Cell::new(false), _phantom: PhantomData, }) diff --git a/crates/fiber/src/unix.rs b/crates/fiber/src/unix.rs index c14a188f50..0cc57ca319 100644 --- a/crates/fiber/src/unix.rs +++ b/crates/fiber/src/unix.rs @@ -75,7 +75,7 @@ impl Fiber { Ok(fiber) } - pub fn new_with_stack(top_of_stack: *mut u8, func: F) -> Self + pub fn new_with_stack(top_of_stack: *mut u8, func: F) -> io::Result where F: FnOnce(A, &super::Suspend) -> C, { @@ -86,7 +86,7 @@ impl Fiber { fiber.init(func); - fiber + Ok(fiber) } fn init(&self, func: F) diff --git a/crates/fiber/src/windows.rs b/crates/fiber/src/windows.rs index c40fb8aeb0..b2d657eb88 100644 --- a/crates/fiber/src/windows.rs +++ b/crates/fiber/src/windows.rs @@ -3,6 +3,7 @@ use std::cell::Cell; use std::io; use std::ptr; use winapi::shared::minwindef::*; +use winapi::shared::winerror::ERROR_NOT_SUPPORTED; use winapi::um::fibersapi::*; use winapi::um::winbase::*; @@ -66,12 +67,11 @@ impl Fiber { } } - pub fn new_with_stack(_top_of_stack: *mut u8, _func: F) -> Self + pub fn new_with_stack(_top_of_stack: *mut u8, _func: F) -> io::Result where F: FnOnce(A, &super::Suspend) -> C, { - // Windows fibers have no support for custom stacks - unimplemented!() + Err(io::Error::from_raw_os_error(ERROR_NOT_SUPPORTED as i32)) } pub(crate) fn resume(&self, result: &Cell>) {