Git Product home page Git Product logo

Comments (8)

tanriol avatar tanriol commented on August 20, 2024

You need to require Send, for example, with trait MyTrait: Send {}

from gotham.

msrd0 avatar msrd0 commented on August 20, 2024

Alternatively, you could also store Vec<Box<dyn MyTrait + Send>> if you don't want Send to be a supertrait of MyTrait.

from gotham.

allevo avatar allevo commented on August 20, 2024

Wow!! thanks a lot for the quick answers!

And what if RequestCounter is a generc struct?

#[derive(Clone, StateData)] // <--- this line goes to error
struct RequestCounter<T> {
    inner: Arc<Mutex<T>>,
}

I tried to put T: Send but is not sufficient

the parameter type `T` may not live long enough
...so that the type `T` will meet its required lifetime boundsrustcE0310
main.rs(27, 24): consider adding an explicit lifetime bound...: `T: 'static + `

Why is the error suggesting me to consider + 'static ? I wouldn't like to that.

from gotham.

tanriol avatar tanriol commented on August 20, 2024

StateData requires Any, which requires 'static. Sorry, I don't think there's any reasonable way around this requirement at the moment.

from gotham.

allevo avatar allevo commented on August 20, 2024

Oki not a problem: I'll duplicate "RequestCounter" for every Service I need.

But why StateData needs to be Any?

from gotham.

msrd0 avatar msrd0 commented on August 20, 2024

Can't you just put that requirement on the type parameter? Like

#[derive(Clone, StateData)]
struct RequestCounter<T: Send + 'static> {
    inner: Arc<Mutex<T>>
}

from gotham.

msrd0 avatar msrd0 commented on August 20, 2024

If that doesn't work, you can still implement StateData manually:

struct RequestCounter<T>(Arc<Mutex<T>>);

impl<T> StateData for RequestCounter<T>
where
    T: Send + 'static
{}

from gotham.

allevo avatar allevo commented on August 20, 2024

thanks for the help!

from gotham.

Related Issues (20)

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.