Coder Social home page Coder Social logo

Comments (4)

mhammond avatar mhammond commented on June 18, 2024 1

You don't want Arc<Url>, just plain Url - Arc<> is only used when passing objects/interfaces, but in this example it's a plain old string.

from uniffi-rs.

linabutler avatar linabutler commented on June 18, 2024 1

Hi @KronicDeth, thanks for the issue! It's the Arc that's tripping it up: Socket::url returns an Arc<Url>, but UniffiCustomTypeConverter is implemented for Url, not Arc<Url>.

If you change Socket::url to return a Url:

/// The `url` passed to [Socket::spawn]
pub fn url(&self) -> Url {
    (*self.url).clone()
}

I think it should work!

Gory details: I don't think it's possible to safely implement UniffiCustomTypeConverter for an Arc<T>. An Arc is a pointer to a specific location in memory, so the type converter would need to roundtrip that pointer through foreign codeβ€”not just the value it points to. UniFFI does this in its generated bindings for interface / object types, using the unsafe Arc::{into_raw, from_raw} on the Rust side, and a wrapper class on the foreign side, but we can't do that in a safe and generic way for custom types.

from uniffi-rs.

linabutler avatar linabutler commented on June 18, 2024

Oops, sorry, I saw @mhammond already replied as I was typing my comment! πŸ˜…

from uniffi-rs.

KronicDeth avatar KronicDeth commented on June 18, 2024

@linabutler the pre-uniffi code returned Arc<Url> to try to be memory efficient, but you and @mhammond make a good point that it has to make a String over the FFI even if we use java.net.Url in Kotlin or URL in Swift, so it really doesn't matter being efficient with Arc<Url>.

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