Coverage for wasmtime/component/_resource_type.py: 96%

24 statements  

« prev     ^ index     » next       coverage.py v7.11.3, created at 2025-12-01 19:40 +0000

1from .. import _ffi as ffi, WasmtimeError 

2from ctypes import POINTER 

3import ctypes 

4from wasmtime import Managed 

5 

6 

7class ResourceType(Managed["ctypes._Pointer[ffi.wasmtime_component_resource_type_t]"]): 

8 def __init__(self) -> None: 

9 raise WasmtimeError("Cannot directly construct a `ResourceType`") 

10 

11 def _delete(self, ptr: "ctypes._Pointer[ffi.wasmtime_component_resource_type_t]") -> None: 

12 ffi.wasmtime_component_resource_type_delete(ptr) 

13 

14 @classmethod 

15 def _from_ptr(cls, ptr: "ctypes._Pointer[ffi.wasmtime_component_resource_type_t]") -> "ResourceType": 

16 if not isinstance(ptr, POINTER(ffi.wasmtime_component_resource_type_t)): 

17 raise TypeError("wrong pointer type") 

18 ty: "ResourceType" = cls.__new__(cls) 

19 ty._set_ptr(ptr) 

20 return ty 

21 

22 @classmethod 

23 def host(cls, val: int) -> "ResourceType": 

24 """ 

25 Creates a new `ResourceType` representing a host-defined resource 

26 identified by the integer identifier `val` given. 

27 """ 

28 ptr = ffi.wasmtime_component_resource_type_new_host(val) 

29 return cls._from_ptr(ptr) 

30 

31 def __eq__(self, other: object) -> bool: 

32 if not isinstance(other, ResourceType): 

33 return False 

34 return ffi.wasmtime_component_resource_type_equal(self.ptr(), other.ptr())