Giter VIP home page Giter VIP logo

Comments (5)

Hoverbear avatar Hoverbear commented on June 19, 2024

Hmmm can you give an example of what you mean?

from getset.

jon-zu avatar jon-zu commented on June 19, 2024

I was implementing a frame for a network protocol. It has multiple versions in the end each
frame has some fields which are the same for all frames like this:
https://play.rust-lang.org/?gist=f9169919078c4e5b42a142c71cc6e316&version=stable

It would be much nicer to write something like this:

trait Frame {
   #[get] #[set]
    field1: u32
}

struct Frame1 {
   #[get] #[set]
    field1: u32
}

However a few problems arrise:

1:
I don't think a trait can contain a field like this.
However I don't know If It is possible to write fields like this into the trait most likely there is no way. Also It could be very confusing.

2:
The field in the struct needs to know which trait It implements. This can be very complex because a trait could have generic type parameters.

from getset.

Hoverbear avatar Hoverbear commented on June 19, 2024

Hmm yes you can't actually have fields in traits, only associated types and const values. :(

from getset.

Boscop avatar Boscop commented on June 19, 2024

And #[derive] also can't be used on traits, right?

from getset.

Hoverbear avatar Hoverbear commented on June 19, 2024

True. I think this is unattainable. :(

from getset.

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.