GithubHelp home page GithubHelp logo

Comments (4)

littledivy avatar littledivy commented on June 12, 2024

deno_bindgen is for runtime FFI. For embedding usecases, you should use deno_ops: https://github.com/denoland/deno_core/tree/main/ops

An example can be found here: https://github.com/denoland/deno_core/blob/main/core/examples/hello_world.rs

The repository for issues related to deno_ops is denoland/deno_core

from deno_bindgen.

joshtriplett avatar joshtriplett commented on June 12, 2024

@littledivy I had already looked at deno_ops (and for that matter the version exported from deno_core as op2). That makes it very easy to export individual functions from Rust to Deno. However, that then requires writing a JS or TS module that wraps those ops, to provide types and methods. What I was hoping for was the ability to export an ES6 module from Rust, similarly to what deno_bindgen provides or what rquickjs provides, without having to write those two wrappers (a Rust wrapper for each method exposing it as a function, and a JS/TS wrapper for each function turning it back into a method).

Ideally, I'd love to write something like this,:

#[deno_core::something(my_es6_module)]
mod my_module {
    #[deno_core::something_else]
    struct SomeType {
        field: Type,
    }

    #[deno_core::something]
    impl SomeType {
        fn new() -> Self { todo!() }
        fn method(&self, arg: Abc) { todo!() }
        fn another_method(&mut self, arg: Xyz) { todo!() }
    }

    // optionally some module initialization code, other types, constants, functions, etc
}

my_es6_module::init_ops_and_esm()

Right now, if I already have that type, I have to write three ops, export those in an extension, and write a JS/TS file defining a type with methods wrapping those three ops.

Is this something that just doesn't exist today? Is anything like this on the roadmap?

from deno_bindgen.

bartlomieju avatar bartlomieju commented on June 12, 2024

Hey @joshtriplett. Something like this currently doesn't exist. Not sure about the roadmap at the moment, but I know that both @littledivy and @mmastrac have been discussion something like that as a potential new feature. So unfortunately for now you'll have to resort to writing the JS/TS glue code.

from deno_bindgen.

mmastrac avatar mmastrac commented on June 12, 2024

I've got some ideas on how we can extend our op system to do that. We're not too far off, and we recently landed the first bits of support for cpp_gc which was the last missing piece to integrate with GC.

from deno_bindgen.

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.