Have new_with_stack impls return io::Result.

This commit is contained in:
Peter Huene
2021-03-03 13:27:56 -08:00
parent 4e83392070
commit 5ee2b8742a
3 changed files with 6 additions and 6 deletions

View File

@@ -66,7 +66,7 @@ impl<'a, Resume, Yield, Return> Fiber<'a, Resume, Yield, Return> {
func: impl FnOnce(Resume, &Suspend<Resume, Yield, Return>) -> Return + 'a, func: impl FnOnce(Resume, &Suspend<Resume, Yield, Return>) -> Return + 'a,
) -> io::Result<Fiber<'a, Resume, Yield, Return>> { ) -> io::Result<Fiber<'a, Resume, Yield, Return>> {
Ok(Fiber { 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), done: Cell::new(false),
_phantom: PhantomData, _phantom: PhantomData,
}) })

View File

@@ -75,7 +75,7 @@ impl Fiber {
Ok(fiber) Ok(fiber)
} }
pub fn new_with_stack<F, A, B, C>(top_of_stack: *mut u8, func: F) -> Self pub fn new_with_stack<F, A, B, C>(top_of_stack: *mut u8, func: F) -> io::Result<Self>
where where
F: FnOnce(A, &super::Suspend<A, B, C>) -> C, F: FnOnce(A, &super::Suspend<A, B, C>) -> C,
{ {
@@ -86,7 +86,7 @@ impl Fiber {
fiber.init(func); fiber.init(func);
fiber Ok(fiber)
} }
fn init<F, A, B, C>(&self, func: F) fn init<F, A, B, C>(&self, func: F)

View File

@@ -3,6 +3,7 @@ use std::cell::Cell;
use std::io; use std::io;
use std::ptr; use std::ptr;
use winapi::shared::minwindef::*; use winapi::shared::minwindef::*;
use winapi::shared::winerror::ERROR_NOT_SUPPORTED;
use winapi::um::fibersapi::*; use winapi::um::fibersapi::*;
use winapi::um::winbase::*; use winapi::um::winbase::*;
@@ -66,12 +67,11 @@ impl Fiber {
} }
} }
pub fn new_with_stack<F, A, B, C>(_top_of_stack: *mut u8, _func: F) -> Self pub fn new_with_stack<F, A, B, C>(_top_of_stack: *mut u8, _func: F) -> io::Result<Self>
where where
F: FnOnce(A, &super::Suspend<A, B, C>) -> C, F: FnOnce(A, &super::Suspend<A, B, C>) -> C,
{ {
// Windows fibers have no support for custom stacks Err(io::Error::from_raw_os_error(ERROR_NOT_SUPPORTED as i32))
unimplemented!()
} }
pub(crate) fn resume<A, B, C>(&self, result: &Cell<RunResult<A, B, C>>) { pub(crate) fn resume<A, B, C>(&self, result: &Cell<RunResult<A, B, C>>) {