1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! Guest Contract Handle — index-based handle to a registered guest contract.
//!
//! This module defines `GuestContractHandle`, the handle returned by `find_guest_contract`
//! and passed to `resolve_guest_contract` to obtain a `GuestContractInterface`.
//!
//! # Who provides
//! The registry creates handles during guest contract registration.
//!
//! # Who calls
//! Host code calls `find_guest_contract` to obtain handles, then `resolve_guest_contract`
//! to get the interface.
//!
//! # Ownership
//! Handles are copyable (an index plus a generation counter). No ownership tracking.
//!
//! # Lifetime
//! Valid until the contract is unregistered or the bundle is unloaded. Each
//! registry slot carries a generation counter that is bumped whenever the slot is
//! vacated on unload, so a handle minted against an earlier generation can be
//! detected as stale even after its index is recycled by a later registration.
//! Use `resolve_guest_contract` to check validity — returns null / StaleHandle if stale.
/// Opaque handle to a registered guest contract.
///
/// The handle pairs the slot `index` with the `generation` the slot held when the
/// handle was minted. `resolve_guest_contract` rejects a handle whose `generation`
/// no longer matches the slot's current generation (the slot was vacated on unload
/// and the index possibly reused), returning `StaleHandle`. Out-of-bounds or empty-slot
/// indices return InvalidHandle.
///
/// # Naming
/// Named `GuestContractHandle` for consistency with `GuestContractInterface`
/// and `GuestContractInstance`.
///
/// # Layout
/// - `index`: Slot index in the registry (u32, offset 0)
/// - `generation`: Slot generation the handle was minted against (u32, offset 4)
///
/// # Safety
/// Handles become stale after unload. Call `resolve_guest_contract` to validate.
/// Returns null pointer if the handle is invalid.