Coder Social home page Coder Social logo

Comments (6)

jamesmunns avatar jamesmunns commented on July 24, 2024 3

I believe this will help in the future: rust-lang/rust#34511

In the future, I would suggest that we use boxed closures rather than static handlers.

from coap-rs.

Covertness avatar Covertness commented on July 24, 2024 1

Copy isn't necessary in #4

from coap-rs.

Covertness avatar Covertness commented on July 24, 2024

@ptxmac I think this will be changed in #4 . The handler would be an instance of a struct that could store some variables. Just like this example.

from coap-rs.

ptxmac avatar ptxmac commented on July 24, 2024

I've looked a bit more on my problem. It looks like 'static isn't the problem. I would like to use a closure as a handler so I can capture some local state, but closures doesn't satisfy Copy.

I looked at the handle trait in Iron: https://github.com/iron/iron/blob/master/src/middleware/mod.rs#L58 and they managed to do it without Copy which allows this example to work: https://github.com/iron/iron/blob/master/examples/redirect.rs

from coap-rs.

jamesmunns avatar jamesmunns commented on July 24, 2024

Yeah, I'm struggling with lifetimes as well. I've kind of hit a wall where I need to clone my "router" struct every time a function is dispatched (so it can be moved into the handler closure), or it needs to have static lifetime. I need to study how the iron handler works a little better.

I've thought about using box'd closures, but I haven't used those yet. You can see what I have here: https://github.com/Covertness/coap-rs/compare/master...jamesmunns:coap-router?expand=1 - but like I said, I hit a bit of a wall when I try to integrate the router (it works well on its own, but trying to get it to work interchangably with a 'static function handler is more difficult than I thought.

I'm open to any thoughts or suggestions.

from coap-rs.

Covertness avatar Covertness commented on July 24, 2024

handler has removed static #47

from coap-rs.

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.