Skip to content

Implement DerefAsync and DerefMutAsync as Deref and DerefMut in async context #50458

Closed
@ijsgaus

Description

@ijsgaus

Introduce traits:

pub trait DerefAsync {
    type Target: Deref<Target::T>;
    async fn derefAsync(&self) -> Async<T>;
}

impl Deref for T: DerefAsync<Target::TOut> + TOut: Deref<Target :: TOut1>
{
   type Target : Async<TOut1>
   fn deref(&self) {
      self.derefAsync().AndAlso(move |t| t.deref());
   }
}

Add support for awaiting derefs. This can be very useful, EG, in async realization of lazy pattern:

   let y = 5;
   let lazy = async_lazy!(y, async |a| await!(a + 2));  
   let x : i32 = await!(lazy);

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions