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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* Copyright (c) 2025 eligamii.
* Licenced under the MIT licence. See the LICENCE file in the project for full licence information
*/
use ;
use quote;
use crateimpl_object;
use crateimpl_object_impl;
/// Add inheritance capabilities to your struct.
///
/// # Syntax
/// ```ignore
/// #[oors::object]
/// struct T { /* ... */ }
///
/// #[oors::object(parent = T)]
/// struct T2 { /* ... */ } // First field will be _base: T
/// ```
/// ---
///
/// # How it works
/// This macro will generate and implement various traits + a macro to allow structs to be
/// safely converted to other compatible structs:
/// - `IsA</* immediate parent */> for T`: Allows at compile time for `T` to have access to parent
/// structs' methods and fields, and to be safely converted to parent structs
/// - `__*Accessors`: Methods to have direct and easy access to field of `T` and all its parents
/// - `__*Builders`: Methods to easily initialize the struct using the builder pattern
/// - `__oors_recursive_impl_*!(/* type */)`: Generated macro to implement `IsA</* all parents of T */>` to `T` and its children
///
/// - `Object`: Allows at runtime to know what is the actual type + the parents of `T` when inside a `Typed<T>`
///
/// **Notes:**<br/>
/// - This macro will also cause the object to have a C layout (`#[repr(C)]`) to ensure predictability
/// - (Unless the feature `nightly` is enabled) If you inherit from an object (`C`) from a foreign module/crate (`mod1`), this macro requires importing the module and all
/// modules containing parent of `C` using the wildcard syntax:
/// ```ignore
/// // prefer `pub use` so other modules doesn't have to `use` `mod1` or `parent_of_c`
/// // to make a child struct of `D`
/// pub use mod1::*;
/// pub use crate_b::parent_of_c::*;
///
/// // Will use __oors_recursive_impl_C!(...) which
/// // will use __oors_recursive_impl_<parent of C>!()
/// // etc.
/// #[oors::object(parent = C)]
/// struct D;
/// ```
/// (if `nightly` is enabled, the macro will generate `__oors_recursive_impl_*!()` as hygienic `pub macro`
/// removing the need of importing anything other than the `__oors_recursive_impl_</* immediate parent */>` itself)
/// Generate implementation for both a struct itself and any child type of the struct.
///
/// # Syntax
/// ```ignore
/// struct T;
/// #[oors::object_impl] impl T { /* ... */ }
/// #[oors::object_impl(pub)] impl T { /* ... */ }
/// #[oors::object_impl(/* any visibility modifier */)] impl T { /* ... */ }
/// ```
///
/// ---
///
/// # How it works
/// It simply automatically puts every instance methods into a generated `<visibility modifier> trait __TImpl where Self: IsA<T>` trait.
/// The visibility modifier is for the
/// Abstracts one `use <root of crate of object>::__oors__recursive_impl_<object name>` statement.
/// You can also use the `object_use!` macro to achieve the same result on multiple `use` statements
///
/// Usage
/// ```ignore
/// #[obj_use] use path::to::Object; // <- Must use the path::to:Struct pattern
/// #[obj_use] pub use path::to::other::Object;
/// // #[obj_use] pub use path::to::{Object} won't compile
/// ```