Debian Codegraph @

third_party/rust/uniffi_bindgen/src/bindings/python/templates/CallbackInterfaceRuntime.py

raw
1 # Magic number for the Rust proxy to call using the same mechanism as every other method,
2 # to free the callback once it's dropped by Rust.
3 _UNIFFI_IDX_CALLBACK_FREE = 0
4 # Return codes for callback calls
5 _UNIFFI_CALLBACK_SUCCESS = 0
6 _UNIFFI_CALLBACK_ERROR = 1
7 _UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2
8
9 class _UniffiCallbackInterfaceFfiConverter:
10 _handle_map = _UniffiHandleMap()
11
12 @classmethod
13 def lift(cls, handle):
14 return cls._handle_map.get(handle)
15
16 @classmethod
17 def read(cls, buf):
18 handle = buf.read_u64()
19 cls.lift(handle)
20
21 @classmethod
22 def check_lower(cls, cb):
23 pass
24
25 @classmethod
26 def lower(cls, cb):
27 handle = cls._handle_map.insert(cb)
28 return handle
29
30 @classmethod
31 def write(cls, cb, buf):
32 buf.write_u64(cls.lower(cb))