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
//! This type can be used with `bun_ptr::Owned` to model "maybe owned" pointers:
//!
//! ```ignore
//! // Either owned by the default allocator, or borrowed
//! type MaybeOwnedFoo = bun_ptr::OwnedIn<Foo, bun_alloc::MaybeOwned<bun_alloc::DefaultAllocator>>;
//!
//! let owned_foo: MaybeOwnedFoo = MaybeOwnedFoo::new(make_foo());
//! let borrowed_foo: MaybeOwnedFoo = MaybeOwnedFoo::from_raw_in(some_foo_ptr, MaybeOwned::init_borrowed());
//!
//! drop(owned_foo); // calls `Foo::drop` and frees the memory
//! drop(borrowed_foo); // no-op
//! ```
//!
//! This type is a `GenericAllocator`; see `src/allocators.zig`.
//!
//! PORT NOTE: Zig modelled this over `Nullable<A>` / `Borrowed<A>` allocator
//! adaptors. With `#[global_allocator]`, "owned" reduces to "drop the box,
//! borrowed = leak"; the generic allocator threading is dropped. The struct
//! keeps the `Option<A>` shape so callers that pattern-match on
//! `is_owned()` keep working.
/// See module docs.
// Zig: `pub const Borrowed = MaybeOwned(BorrowedParent);`
// Rust has no stable inherent associated types, so expose as a free alias.
// `Borrowed<A>` collapsed to `()` — borrows carry no allocator state.
pub type MaybeOwnedBorrowed = ;
// Zig `deinit` only forwarded to `bun.memory.deinit(parent_alloc)` on the owned field.
// Per PORTING.md (Idiom map: `pub fn deinit`), that is exactly field drop glue on
// `_parent: Option<A>`, so no explicit `Drop` impl — keeping one would also forbid
// moving `self._parent` out in `into_parent(self)`.
// ported from: src/bun_alloc/maybe_owned.zig