|
6 | 6 | //! definitions contained within.
|
7 | 7 | //! Some helper functions allow to extract useful information from [`Cursor`]s.
|
8 | 8 | use constructor::ConstructorDefinition;
|
9 |
| -use derive_more::{Display, From}; |
| 9 | +use derive_more::{Display, From, IsVariant}; |
10 | 10 | use enumeration::EnumDefinition;
|
11 | 11 | use error::ErrorDefinition;
|
12 | 12 | use event::EventDefinition;
|
@@ -169,7 +169,7 @@ pub enum Parent {
|
169 | 169 | }
|
170 | 170 |
|
171 | 171 | /// A source item's definition
|
172 |
| -#[derive(Debug, From)] |
| 172 | +#[derive(Debug, From, IsVariant)] |
173 | 173 | pub enum Definition {
|
174 | 174 | Constructor(ConstructorDefinition),
|
175 | 175 | Enumeration(EnumDefinition),
|
@@ -238,72 +238,143 @@ impl Definition {
|
238 | 238 | }
|
239 | 239 | }
|
240 | 240 |
|
241 |
| - /// Retrieve the inner constructor definition |
| 241 | + /// Convert to the inner constructor definition |
242 | 242 | #[must_use]
|
243 |
| - pub fn as_constructor(self) -> Option<ConstructorDefinition> { |
| 243 | + pub fn to_constructor(self) -> Option<ConstructorDefinition> { |
244 | 244 | match self {
|
245 | 245 | Definition::Constructor(def) => Some(def),
|
246 | 246 | _ => None,
|
247 | 247 | }
|
248 | 248 | }
|
249 | 249 |
|
250 |
| - /// Retrieve the inner enum definition |
| 250 | + /// Convert to the inner enum definition |
251 | 251 | #[must_use]
|
252 |
| - pub fn as_enum(self) -> Option<EnumDefinition> { |
| 252 | + pub fn to_enum(self) -> Option<EnumDefinition> { |
253 | 253 | match self {
|
254 | 254 | Definition::Enumeration(def) => Some(def),
|
255 | 255 | _ => None,
|
256 | 256 | }
|
257 | 257 | }
|
258 | 258 |
|
259 |
| - /// Retrieve the inner error definition |
| 259 | + /// Convert to the inner error definition |
260 | 260 | #[must_use]
|
261 |
| - pub fn as_error(self) -> Option<ErrorDefinition> { |
| 261 | + pub fn to_error(self) -> Option<ErrorDefinition> { |
262 | 262 | match self {
|
263 | 263 | Definition::Error(def) => Some(def),
|
264 | 264 | _ => None,
|
265 | 265 | }
|
266 | 266 | }
|
267 | 267 |
|
268 |
| - /// Retrieve the inner event definition |
| 268 | + /// Convert to the inner event definition |
269 | 269 | #[must_use]
|
270 |
| - pub fn as_event(self) -> Option<EventDefinition> { |
| 270 | + pub fn to_event(self) -> Option<EventDefinition> { |
271 | 271 | match self {
|
272 | 272 | Definition::Event(def) => Some(def),
|
273 | 273 | _ => None,
|
274 | 274 | }
|
275 | 275 | }
|
276 | 276 |
|
277 |
| - /// Retrieve the inner function definition |
| 277 | + /// Convert to the inner function definition |
278 | 278 | #[must_use]
|
279 |
| - pub fn as_function(self) -> Option<FunctionDefinition> { |
| 279 | + pub fn to_function(self) -> Option<FunctionDefinition> { |
280 | 280 | match self {
|
281 | 281 | Definition::Function(def) => Some(def),
|
282 | 282 | _ => None,
|
283 | 283 | }
|
284 | 284 | }
|
285 | 285 |
|
286 |
| - /// Retrieve the inner modifier definition |
| 286 | + /// Convert to the inner modifier definition |
287 | 287 | #[must_use]
|
288 |
| - pub fn as_modifier(self) -> Option<ModifierDefinition> { |
| 288 | + pub fn to_modifier(self) -> Option<ModifierDefinition> { |
289 | 289 | match self {
|
290 | 290 | Definition::Modifier(def) => Some(def),
|
291 | 291 | _ => None,
|
292 | 292 | }
|
293 | 293 | }
|
294 | 294 |
|
295 |
| - /// Retrieve the inner struct definition |
| 295 | + /// Convert to the inner struct definition |
296 | 296 | #[must_use]
|
297 |
| - pub fn as_struct(self) -> Option<StructDefinition> { |
| 297 | + pub fn to_struct(self) -> Option<StructDefinition> { |
298 | 298 | match self {
|
299 | 299 | Definition::Struct(def) => Some(def),
|
300 | 300 | _ => None,
|
301 | 301 | }
|
302 | 302 | }
|
303 | 303 |
|
304 |
| - /// Retrieve the inner variable declaration |
| 304 | + /// Convert to the inner variable declaration |
305 | 305 | #[must_use]
|
306 |
| - pub fn as_variable(self) -> Option<VariableDeclaration> { |
| 306 | + pub fn to_variable(self) -> Option<VariableDeclaration> { |
| 307 | + match self { |
| 308 | + Definition::Variable(def) => Some(def), |
| 309 | + _ => None, |
| 310 | + } |
| 311 | + } |
| 312 | + /// Reference to the inner constructor definition |
| 313 | + #[must_use] |
| 314 | + pub fn as_constructor(&self) -> Option<&ConstructorDefinition> { |
| 315 | + match self { |
| 316 | + Definition::Constructor(def) => Some(def), |
| 317 | + _ => None, |
| 318 | + } |
| 319 | + } |
| 320 | + |
| 321 | + /// Reference to the inner enum definition |
| 322 | + #[must_use] |
| 323 | + pub fn as_enum(&self) -> Option<&EnumDefinition> { |
| 324 | + match self { |
| 325 | + Definition::Enumeration(def) => Some(def), |
| 326 | + _ => None, |
| 327 | + } |
| 328 | + } |
| 329 | + |
| 330 | + /// Reference to the inner error definition |
| 331 | + #[must_use] |
| 332 | + pub fn as_error(&self) -> Option<&ErrorDefinition> { |
| 333 | + match self { |
| 334 | + Definition::Error(def) => Some(def), |
| 335 | + _ => None, |
| 336 | + } |
| 337 | + } |
| 338 | + |
| 339 | + /// Reference to the inner event definition |
| 340 | + #[must_use] |
| 341 | + pub fn as_event(&self) -> Option<&EventDefinition> { |
| 342 | + match self { |
| 343 | + Definition::Event(def) => Some(def), |
| 344 | + _ => None, |
| 345 | + } |
| 346 | + } |
| 347 | + |
| 348 | + /// Reference to the inner function definition |
| 349 | + #[must_use] |
| 350 | + pub fn as_function(&self) -> Option<&FunctionDefinition> { |
| 351 | + match self { |
| 352 | + Definition::Function(def) => Some(def), |
| 353 | + _ => None, |
| 354 | + } |
| 355 | + } |
| 356 | + |
| 357 | + /// Reference to the inner modifier definition |
| 358 | + #[must_use] |
| 359 | + pub fn as_modifier(&self) -> Option<&ModifierDefinition> { |
| 360 | + match self { |
| 361 | + Definition::Modifier(def) => Some(def), |
| 362 | + _ => None, |
| 363 | + } |
| 364 | + } |
| 365 | + |
| 366 | + /// Reference to the inner struct definition |
| 367 | + #[must_use] |
| 368 | + pub fn as_struct(&self) -> Option<&StructDefinition> { |
| 369 | + match self { |
| 370 | + Definition::Struct(def) => Some(def), |
| 371 | + _ => None, |
| 372 | + } |
| 373 | + } |
| 374 | + |
| 375 | + /// Reference to the inner variable declaration |
| 376 | + #[must_use] |
| 377 | + pub fn as_variable(&self) -> Option<&VariableDeclaration> { |
307 | 378 | match self {
|
308 | 379 | Definition::Variable(def) => Some(def),
|
309 | 380 | _ => None,
|
|
0 commit comments