Header File - [X] functions with owned arguments should use - [X] :+1: `&&` in guest imported functions - [X] `R::Owned` in guest exported func. - [X] functions returning resources should return `R::Owned` in guest exported func. Code: - [X] :+1: functions returning resources (g.i.) need to add `wit::ResourceImportBase{ret}` has to happen before Return is called - [ ] functions accepting a reference_wrapper need to unwrap the args `.get()` - [ ] functions consuming resource (g.i.) should use `&&` on args and `.into_handle()` - [X] :+1: constructors (g.e.) should use `return result0.release()->into_handle();` - [ ] functions returning resources (g.e.) should `.release()` the unique_ptr - [ ] functions borrowing/owning res. (g.e.) should use `int8_t* arg0` (larger issue) - [ ] functions borrowing args (g.e.) should create a cref: `std::cref(*(T const*)arg0)` - [ ] functions consuming res. (g.e.) should deregister them: ``` auto obj = T::Owned((T*)arg0); obj->into_handle(); ``` - [ ] and move the args `func(std::move(obj))` - [X] create a construction forwarder: `T(wit::ResourceImportBase&&b) : wit::ResourceImportBase(std::move(b)) {}` User Class Templates - [x] should define the Owned type: ``` struct Deleter { void operator()(R* ptr) const { R::Dtor(ptr); } }; typedef std::unique_ptr<R, R::Deleter> Owned; ``` - [X] New should return an Owned `static Owned New(uint32_t a) { return Owned(new R(a)); }`
Header File
&&in guest imported functionsR::Ownedin guest exported func.R::Ownedin guest exported func.Code:
wit::ResourceImportBase{ret}has to happen before Return is called
.get()&&on args and.into_handle()return result0.release()->into_handle();.release()the unique_ptrint8_t* arg0(larger issue)std::cref(*(T const*)arg0)func(std::move(obj))T(wit::ResourceImportBase&&b) : wit::ResourceImportBase(std::move(b)) {}User Class Templates
static Owned New(uint32_t a) { return Owned(new R(a)); }