Git Product home page Git Product logo

Comments (3)

teon avatar teon commented on May 23, 2024

Let's wait on @wojcik91 update in #12

from wireguard-rs.

Ange-Cesari avatar Ange-Cesari commented on May 23, 2024

Hey @teon and @wojcik91 ,

I'd like to bring a little update regarding this matter.
I tried to somewhat play with the librairy, adding the clone trait and I also tried to bring the Copy trait (The copy trait is a way more complicated thing to implement because you need to add the copy trait for a lot of things and you can't because of a vector that can't be copied bit to bit.

For the main concern :

The clone is not mandatory for 99% of the use cases because you can borrow a Host and make it mutable if it's still not enough, you can make the Host type a type reference and you can also reference to the object host itself, so you can give it to multiple functions. (This way you can avoid the borrow / value moved problem)

However, there are some really particular cases that might need the clone trait (you want to perform a very particular operation on the host, or on the peer, and it's irreversible, or it's a side operation that doesn't need to continue with the structure afterward, then the clone trait can be interesting. You can also use a to_owned on the struct but it performs actually a .clone().

It's not related to the library but you have to keep in mind that if you have a Host A, then you clone to a Host B, you'll be able to modify both in parallel but every changes that are made to Host A won't be mirrored to the Host B. And vice & versa. Which means that you can't clone Host A to give Host B to another function and expect to use the Host A with the changes. (for instance, peer creation)

Finally, I think adding the clone trait (and copy trait when possible) is a must because it can save a lot of time and allows to pull the library from crates.io with the changes already made instead of modifying it locally.

Can I have your feedback on the possibility of doing the integration of the clone trait to the structures ?

Best,
Ange

from wireguard-rs.

wojcik91 avatar wojcik91 commented on May 23, 2024

Hi.
I added the Clone trait to Host struct and specific interface implementations in #20.

When it comes to the WGApi struct itself, making it Clone would require a more significant refactor or pulling in an additional crate (like dyn-clone) due to the need for object-safety, so I don't think we'll add it at this point in time.

from wireguard-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.