Coder Social home page Coder Social logo

Cloning Destination/Source? about coremidi HOT 4 CLOSED

chris-zen avatar chris-zen commented on June 1, 2024
Cloning Destination/Source?

from coremidi.

Comments (4)

Boddlnagg avatar Boddlnagg commented on June 1, 2024 1

I was finally able to work on this again, and it turns out that Arc<Destination> works just fine 👍

from coremidi.

chris-zen avatar chris-zen commented on June 1, 2024

@Boddlnagg that integer is an opaque handler to a CoreMIDI resource, if we clone it, then, there would be two owners for the same object, which violates the rules from the borrow checker.

Could you use an Arc<Destination> ?

I think I am doing something similar here:

The alternative would be to use certain features from the CoreMIDI API to retrieve the object unique id, and use it to create a new Destination instance (but this is not fully supported by the rust coremidi lib yet, although you could add the exports yourself).

from coremidi.

Boddlnagg avatar Boddlnagg commented on June 1, 2024

Yes, looking at the definition of Destination, cloning would need to clone all the way down to the underlying Object. And I thought it might be possible, because there's no Drop implementation. So technically the ownership semantics is not encoded in the type (this is somewhat related to #8), but I do understand that this would be a little un-Rust-y. So it's totally okay if you don't want to go that route.

However, thank you for the hint towards Arc<Destination>, I think that should actually work, and if it doesn't, I will use MIDIObjectFindByUniqueID (I can add the export myself, but it would still be nice if you could add something like Destination::from_unique_id, although I don't know whether that would need to be unsafe because you don't know from a unique ID if it actually refers to the right kind of object, right?).

from coremidi.

chris-zen avatar chris-zen commented on June 1, 2024

Please try Arc<Destination> and if it doesn't work for you, we can talk about Destination::from_unique_id. This was in my mind before, but not as a priority thing.
About the unique id not existing anymore I guess this shouldn't be a problem as the factory method could return a Result.

from coremidi.

Related Issues (16)

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.