Giter Club home page Giter Club logo

Comments (3)

lopo12123 avatar lopo12123 commented on September 23, 2024

How about trying #[napi(object)]

look at here, https://napi.rs/docs/concepts/object, #[napi] means class while #[napi(object)] means object

#![deny(clippy::all)]

#[macro_use]
extern crate napi_derive;

#[derive(Clone)]
#[napi(object)]  // change here
pub struct Element {
  pub name: String,
}

#[napi]  // you can keep it if it's a class
pub struct Parent {
  pub elements: Vec<Element>,
}

I copied the above code directly into my project, and it compiled correctly (the content outside the screenshot is my original project, don't worry about it)

image


If your original intention is that Element is a class, then this seems to be a mistake (I'm not sure).

I tried the following code but it failed to compile and I encountered the same error.

#[derive(Clone)]
#[napi(constructor)]  // change here
pub struct Element {
    pub name: String,
}

#[napi]
pub struct Parent {
    pub elements: Vec<Element>,
}

from napi-rs.

bodymindarts avatar bodymindarts commented on September 23, 2024

+1 - I've run into this too!

from napi-rs.

jssblck avatar jssblck commented on September 23, 2024

Running into this as well:

/// The result of the operation.
///
/// A function returning this type indicates that
/// it will attempt to continue through errors,
/// collecting them and returning them alongside
/// any successful results.
///
/// Such functions _should_ only result in an exception
/// due to extreme runtime issues, for example
/// if the process runs out of memory and times out
/// trying to allocate more.
#[derive(Clone, Eq, PartialEq, Debug)]
#[napi(object)]
pub struct Resilient<T, E> {
    pub ok: Option<T>,
    pub errors: Vec<E>,
}

Output snippet from cargo build:

error[E0107]: missing generics for struct `Resilient`
   --> src/lib.rs:151:12
    |
151 | pub struct Resilient<T, E> {
    |            ^^^^^^^^^ expected 2 generic arguments
    |
note: struct defined here, with 2 generic parameters: `T`, `E`
   --> src/lib.rs:151:12
    |
151 | pub struct Resilient<T, E> {
    |            ^^^^^^^^^ -  -
help: add missing generic arguments
    |
151 | pub struct Resilient<T, E><T, E> {
    |                     ++++++

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