@@ -27,7 +27,7 @@ impl<_T> TheWorldPre<_T> {
27
27
pub fn new (
28
28
instance_pre : wasmtime:: component:: InstancePre < _T > ,
29
29
) -> wasmtime:: Result < Self > {
30
- let indices = TheWorldIndices :: new ( instance_pre. component ( ) ) ?;
30
+ let indices = TheWorldIndices :: new ( & instance_pre) ?;
31
31
Ok ( Self { instance_pre, indices } )
32
32
}
33
33
pub fn engine ( & self ) -> & wasmtime:: Engine {
@@ -85,11 +85,6 @@ pub struct TheWorldIndices {
85
85
/// * If you've instantiated the instance yourself already
86
86
/// then you can use [`TheWorld::new`].
87
87
///
88
- /// * You can also access the guts of instantiation through
89
- /// [`TheWorldIndices::new_instance`] followed
90
- /// by [`TheWorldIndices::load`] to crate an instance of this
91
- /// type.
92
- ///
93
88
/// These methods are all equivalent to one another and move
94
89
/// around the tradeoff of what work is performed when.
95
90
///
@@ -108,29 +103,12 @@ const _: () = {
108
103
///
109
104
/// This method may fail if the component does not have the
110
105
/// required exports.
111
- pub fn new (
112
- component : & wasmtime:: component:: Component ,
106
+ pub fn new < _T > (
107
+ _instance_pre : & wasmtime:: component:: InstancePre < _T > ,
113
108
) -> wasmtime:: Result < Self > {
114
- let _component = component;
115
- let interface0 = exports:: foo:: foo:: chars:: GuestIndices :: new ( _component) ?;
116
- Ok ( TheWorldIndices { interface0 } )
117
- }
118
- /// Creates a new instance of [`TheWorldIndices`] from an
119
- /// instantiated component.
120
- ///
121
- /// This method of creating a [`TheWorld`] will perform string
122
- /// lookups for all exports when this method is called. This
123
- /// will only succeed if the provided instance matches the
124
- /// requirements of [`TheWorld`].
125
- pub fn new_instance (
126
- mut store : impl wasmtime:: AsContextMut ,
127
- instance : & wasmtime:: component:: Instance ,
128
- ) -> wasmtime:: Result < Self > {
129
- let _instance = instance;
130
- let interface0 = exports:: foo:: foo:: chars:: GuestIndices :: new_instance (
131
- & mut store,
132
- _instance,
133
- ) ?;
109
+ let _component = _instance_pre. component ( ) ;
110
+ let _instance_type = _instance_pre. instance_type ( ) ;
111
+ let interface0 = exports:: foo:: foo:: chars:: GuestIndices :: new ( _instance_pre) ?;
134
112
Ok ( TheWorldIndices { interface0 } )
135
113
}
136
114
/// Uses the indices stored in `self` to load an instance
@@ -143,6 +121,7 @@ const _: () = {
143
121
mut store : impl wasmtime:: AsContextMut ,
144
122
instance : & wasmtime:: component:: Instance ,
145
123
) -> wasmtime:: Result < TheWorld > {
124
+ let _ = & mut store;
146
125
let _instance = instance;
147
126
let interface0 = self . interface0 . load ( & mut store, & _instance) ?;
148
127
Ok ( TheWorld { interface0 } )
@@ -152,7 +131,7 @@ const _: () = {
152
131
/// Convenience wrapper around [`TheWorldPre::new`] and
153
132
/// [`TheWorldPre::instantiate_async`].
154
133
pub async fn instantiate_async < _T > (
155
- mut store : impl wasmtime:: AsContextMut < Data = _T > ,
134
+ store : impl wasmtime:: AsContextMut < Data = _T > ,
156
135
component : & wasmtime:: component:: Component ,
157
136
linker : & wasmtime:: component:: Linker < _T > ,
158
137
) -> wasmtime:: Result < TheWorld >
@@ -162,14 +141,14 @@ const _: () = {
162
141
let pre = linker. instantiate_pre ( component) ?;
163
142
TheWorldPre :: new ( pre) ?. instantiate_async ( store) . await
164
143
}
165
- /// Convenience wrapper around [`TheWorldIndices::new_instance `] and
144
+ /// Convenience wrapper around [`TheWorldIndices::new `] and
166
145
/// [`TheWorldIndices::load`].
167
146
pub fn new (
168
147
mut store : impl wasmtime:: AsContextMut ,
169
148
instance : & wasmtime:: component:: Instance ,
170
149
) -> wasmtime:: Result < TheWorld > {
171
- let indices = TheWorldIndices :: new_instance ( & mut store , instance) ?;
172
- indices. load ( store, instance)
150
+ let indices = TheWorldIndices :: new ( & instance. instance_pre ( & store ) ) ?;
151
+ indices. load ( & mut store, instance)
173
152
}
174
153
pub fn add_to_linker < T , U > (
175
154
linker : & mut wasmtime:: component:: Linker < T > ,
@@ -295,45 +274,21 @@ pub mod exports {
295
274
///
296
275
/// This constructor can be used to front-load string lookups to find exports
297
276
/// within a component.
298
- pub fn new (
299
- component : & wasmtime:: component:: Component ,
277
+ pub fn new < _T > (
278
+ _instance_pre : & wasmtime:: component:: InstancePre < _T > ,
300
279
) -> wasmtime:: Result < GuestIndices > {
301
- let instance = component
280
+ let instance = _instance_pre
281
+ . component ( )
302
282
. get_export_index ( None , "foo:foo/chars" )
303
283
. ok_or_else ( || {
304
284
anyhow:: anyhow!(
305
285
"no exported instance named `foo:foo/chars`"
306
286
)
307
287
} ) ?;
308
- Self :: _new ( |name| {
309
- component. get_export_index ( Some ( & instance) , name)
310
- } )
311
- }
312
- /// This constructor is similar to [`GuestIndices::new`] except that it
313
- /// performs string lookups after instantiation time.
314
- pub fn new_instance (
315
- mut store : impl wasmtime:: AsContextMut ,
316
- instance : & wasmtime:: component:: Instance ,
317
- ) -> wasmtime:: Result < GuestIndices > {
318
- let instance_export = instance
319
- . get_export_index ( & mut store, None , "foo:foo/chars" )
320
- . ok_or_else ( || {
321
- anyhow:: anyhow!(
322
- "no exported instance named `foo:foo/chars`"
323
- )
324
- } ) ?;
325
- Self :: _new ( |name| {
326
- instance
327
- . get_export_index ( & mut store, Some ( & instance_export) , name)
328
- } )
329
- }
330
- fn _new (
331
- mut lookup : impl FnMut (
332
- & str ,
333
- ) -> Option < wasmtime:: component:: ComponentExportIndex > ,
334
- ) -> wasmtime:: Result < GuestIndices > {
335
288
let mut lookup = move |name| {
336
- lookup ( name)
289
+ _instance_pre
290
+ . component ( )
291
+ . get_export_index ( Some ( & instance) , name)
337
292
. ok_or_else ( || {
338
293
anyhow:: anyhow!(
339
294
"instance export `foo:foo/chars` does \
@@ -354,9 +309,11 @@ pub mod exports {
354
309
mut store : impl wasmtime:: AsContextMut ,
355
310
instance : & wasmtime:: component:: Instance ,
356
311
) -> wasmtime:: Result < Guest > {
312
+ let _instance = instance;
313
+ let _instance_pre = _instance. instance_pre ( & store) ;
314
+ let _instance_type = _instance_pre. instance_type ( ) ;
357
315
let mut store = store. as_context_mut ( ) ;
358
316
let _ = & mut store;
359
- let _instance = instance;
360
317
let take_char = * _instance
361
318
. get_typed_func :: < ( char , ) , ( ) > ( & mut store, & self . take_char ) ?
362
319
. func ( ) ;
0 commit comments