Giter VIP home page Giter VIP logo

async_auto_traits's Introduction

โ˜€๏ธ Solarpunk
๐ŸŒ Open Source advocate
๐Ÿฆ€ Rust developer
๐Ÿง Linux poweruser

Things I created

  • caniuse.rs โ€“ Check which version of Rust stabilized a certain feature
  • turbo.fish โ€“ A little joke website
  • cargo depgraph - Creates graphviz dependency graphs for Rust projects that use Cargo
  • serde_html_form โ€“ Rust crate for (de-)serialization of application/x-www-form-urlencoded data
  • eyeball โ€“ Add observability to your Rust types!
  • hinoki (WIP) โ€“ A simple, yet very flexible static site generator

Things I contributed a lot to

  • Ruma (@ruma) โ€“ Matrix libraries for Rust
  • axum โญ๏ธ โ€“ Rust web application framework
  • tower-http โ€“ Rust HTTP server utilities

async_auto_traits's People

Contributors

jplatte avatar

Watchers

 avatar  avatar  avatar

async_auto_traits's Issues

Enforce no (stable) auto traits are implemented for the returned Future

Currently #[clear] (and maybe also #[set]) do not enforce that as this compiles:

#[async_auto_traits::clear]
async fn foo() {}

fn assert_send(_: impl Send) {}

fn main() {
    assert_send(foo());
}

Because impl Future does not hide auto traits.

The enforcement could be done through something like this (play):

use pin_project_lite::pin_project;
use std::{
    future::Future,
    marker::PhantomData,
    pin::Pin,
    task::{Context, Poll},
};

pin_project! {
    pub struct NotSendButSyncFuture<F: Future> {
        #[pin]
        future: F,
        ghost: PhantomData<*const ()>,
    }
}

unsafe impl<F: Future + Sync> Sync for NotSendButSyncFuture<F> {}

impl<F: Future> NotSendButSyncFuture<F> {
    pub fn new(future: F) -> Self {
        Self {
            future,
            ghost: PhantomData,
        }
    }
}

impl<F: Future> Future for NotSendButSyncFuture<F> {
    type Output = F::Output;

    fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        self.project().future.poll(cx)
    }
}

fn foo() -> impl Future {
    NotSendButSyncFuture::new(async move { todo!() })
}

fn assert_send(_: impl Send) {}

fn main() {
    assert_send(foo());
}

Or something like this (but may not work properly for async fns that have no .await, play):

use std::{future, marker::PhantomData};

async fn foo() {
    let _phantom = PhantomData::<*mut ()>;
    future::ready(()).await;
}

fn assert_send_sync(_: impl Send + Sync) {}

fn main() {
    assert_send_sync(foo());
}

(Moved from rust-lang/rust#82187 (comment), sorry for being off-topic there!)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.