nolife icon indicating copy to clipboard operation
nolife copied to clipboard

Draft: Add Send and Sync

Open dureuill opened this issue 1 year ago • 2 comments

Fixes #18

dureuill avatar May 08 '24 12:05 dureuill

OK got it to work with:

diff --git a/README.md b/README.md
index 0c5a543..8213420 100644
--- a/README.md
+++ b/README.md
@@ -35,7 +35,7 @@ impl<'a> nolife::Family<'a> for MyParsedDataFamily {
 // 2. Define a function that setups the data and its borrowed representation:
 fn my_scope(
     data_source: Vec<u8>, // 👈 all parameters that allow to build a `MyData`
-) -> impl nolife::TopScope<Family = MyParsedDataFamily> // 👈 use the helper type we declared
+) -> impl nolife::TopScope<Family = MyParsedDataFamily, Future: core::future::Future + Send + Sync> // 👈 use the helper type we declared
 {
     nolife::scope!({
         let mut data = MyData(data_source);

Unfortunately:

  1. Associated type bounds are only stabilized in 1.79, which is currently beta, so this code doesn't compile on stable yet
  2. I'm really not sure I like forcing the user to write this code. The error is a bit mysterious when the bound is missing, fixing it requires a good understanding of the behaviour of impl Trait regarding the additional bounds on the types associated with the trait.

Not sure if there's another workaround.

dureuill avatar May 08 '24 12:05 dureuill

TIL

diff --git a/README.md b/README.md
index 0c5a543..f01e4be 100644
--- a/README.md
+++ b/README.md
@@ -35,7 +35,7 @@ impl<'a> nolife::Family<'a> for MyParsedDataFamily {
 // 2. Define a function that setups the data and its borrowed representation:
 fn my_scope(
     data_source: Vec<u8>, // 👈 all parameters that allow to build a `MyData`
-) -> impl nolife::TopScope<Family = MyParsedDataFamily> // 👈 use the helper type we declared
+) -> impl nolife::TopScope<Family = MyParsedDataFamily, Future = impl Send + Sync> // 👈 use the helper type we declared
 {
     nolife::scope!({
         let mut data = MyData(data_source);

Thanks, yandros :heart:

dureuill avatar May 10 '24 15:05 dureuill