• BB_C
    link
    fedilink
    arrow-up
    1
    ·
    6 小时前
    struct SomeFuture;
    
    impl Future for SomeFuture {
      // ....
    }
    
    

    where are you going to “pin metadata”?

    • lad
      link
      fedilink
      English
      arrow-up
      2
      ·
      5 小时前

      I think, they mean:

      pub trait Future {
        // ....
      
        fn put_metadata(...);
      
        fn get_metadata(...);
      }
      

      I find it too magical to be necessary, but I can see how it might be useful. This can be achieved with a wrapper, but will then require you to wrap every future, which is not too convenient

      • BB_C
        link
        fedilink
        arrow-up
        1
        ·
        2 小时前

        It’s not about magic, it’s just not how the abstraction works.

        Let’s have a concrete example, poem::web::Data utilizes opentelemetry::context::FutureExt which has the trait methods with_context() and with_current_context(). But where is the data/context actually stored? In the WithContext struct of course. Because there is no such a thing as pinning (meta)data to a trait.

        @[email protected] ^^

        • orclev@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          38 分钟前

          You do realize FutureExt is a trait right? That’s literally what I’m asking for just with it baked into Future instead of FutureExt.

      • devnev@lemmy.dbzer0.com
        link
        fedilink
        arrow-up
        2
        ·
        2 小时前

        Other languages have ended up introducing it out of practical necessity, e.g. Go’s contexts, JS execution contexts. Pick your poison, although I expect Rust’s general minimal approach will leave it as extra parameters, Go-style.