MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / get_resource

Method get_resource

crates/wasmtime/src/runtime/component/instance.rs:255–272  ·  view source on GitHub ↗

Looks up an exported resource type by name within this [`Instance`]. The `store` argument provided must be the store that this instance lives within and the `name` argument is the lookup key by which to find the exported resource. If the resource is found then `Some` is returned and otherwise `None` is returned. The `name` here can be a string such as `&str` or it can be a [`ComponentExportIndex

(
        &self,
        mut store: impl AsContextMut,
        name: impl ExportLookup,
    )

Source from the content-addressed store, hash-verified

253 ///
254 /// Panics if `store` does not own this instance.
255 pub fn get_resource(
256 &self,
257 mut store: impl AsContextMut,
258 name: impl ExportLookup,
259 ) -> Option<ResourceType> {
260 let store = store.as_context_mut().0;
261 let (instance, export) = self.lookup_export(store, name)?;
262 match export {
263 Export::Type(TypeDef::Resource(id)) => {
264 Some(InstanceType::new(instance).resource_type(*id))
265 }
266 Export::Type(_)
267 | Export::LiftedFunction { .. }
268 | Export::ModuleStatic { .. }
269 | Export::ModuleImport { .. }
270 | Export::Instance { .. } => None,
271 }
272 }
273
274 /// A methods similar to [`Component::get_export`] except for this
275 /// instance.

Callers 8

host_resource_typesFunction · 0.80
guest_resource_typesFunction · 0.80
resource_anyFunction · 0.80
dynamic_typeFunction · 0.80
dynamic_valFunction · 0.80
moduleMethod · 0.80
TESTFunction · 0.80

Calls 4

lookup_exportMethod · 0.80
newFunction · 0.50
as_context_mutMethod · 0.45
resource_typeMethod · 0.45

Tested by 7

host_resource_typesFunction · 0.64
guest_resource_typesFunction · 0.64
resource_anyFunction · 0.64
dynamic_typeFunction · 0.64
dynamic_valFunction · 0.64
TESTFunction · 0.64