Skip to content

Commit 44ba1f1

Browse files
committed
fill out the other intos
Signed-off-by: Daniel King <[email protected]>
1 parent 41d76b9 commit 44ba1f1

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

vortex-dtype/src/dtype.rs

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ impl DType {
334334
}
335335
}
336336

337+
/// Owned version of [as_decimal_opt].
338+
pub fn into_decimal_opt(self) -> Option<DecimalDType> {
339+
if let Decimal(decimal, _) = self {
340+
Some(decimal)
341+
} else {
342+
None
343+
}
344+
}
345+
337346
/// Get the inner element dtype if `self` is a [`DType::List`], otherwise returns `None`.
338347
///
339348
/// Note that this does _not_ return `Some` if `self` is a [`DType::FixedSizeList`].
@@ -345,6 +354,15 @@ impl DType {
345354
}
346355
}
347356

357+
/// Owned version of [as_list_element_opt].
358+
pub fn into_list_element_opt(self) -> Option<Arc<DType>> {
359+
if let List(edt, _) = self {
360+
Some(edt)
361+
} else {
362+
None
363+
}
364+
}
365+
348366
/// Get the inner element dtype if `self` is a [`DType::FixedSizeList`], otherwise returns
349367
/// `None`.
350368
///
@@ -357,6 +375,15 @@ impl DType {
357375
}
358376
}
359377

378+
/// Owned version of [as_fixed_size_list_element_opt].
379+
pub fn into_fixed_size_list_element_opt(self) -> Option<Arc<DType>> {
380+
if let FixedSizeList(edt, ..) = self {
381+
Some(edt)
382+
} else {
383+
None
384+
}
385+
}
386+
360387
/// Get the inner element dtype if `self` is **either** a [`DType::List`] or a
361388
/// [`DType::FixedSizeList`], otherwise returns `None`
362389
pub fn as_any_size_list_element_opt(&self) -> Option<&Arc<DType>> {
@@ -369,6 +396,17 @@ impl DType {
369396
}
370397
}
371398

399+
/// Owned version of [as_any_size_list_element_opt].
400+
pub fn into_any_size_list_element_opt(self) -> Option<Arc<DType>> {
401+
if let FixedSizeList(edt, ..) = self {
402+
Some(edt)
403+
} else if let List(edt, ..) = self {
404+
Some(edt)
405+
} else {
406+
None
407+
}
408+
}
409+
372410
/// Returns the [`StructFields`] from a struct [`DType`].
373411
///
374412
/// # Panics
@@ -381,6 +419,14 @@ impl DType {
381419
vortex_panic!("DType is not a Struct")
382420
}
383421

422+
/// Owned version of [as_struct_fields].
423+
pub fn into_struct_fields(self) -> StructFields {
424+
if let Struct(f, _) = self {
425+
return f;
426+
}
427+
vortex_panic!("DType is not a Struct")
428+
}
429+
384430
/// Get the `StructDType` if `self` is a `StructDType`, otherwise `None`
385431
pub fn as_struct_fields_opt(&self) -> Option<&StructFields> {
386432
if let Struct(f, _) = self {
@@ -390,19 +436,7 @@ impl DType {
390436
}
391437
}
392438

393-
/// Returns the [`StructFields`] from a struct [`DType`].
394-
///
395-
/// # Panics
396-
///
397-
/// If the [`DType`] is not a struct.
398-
pub fn into_struct_fields(self) -> StructFields {
399-
if let Struct(f, _) = self {
400-
return f;
401-
}
402-
vortex_panic!("DType is not a Struct")
403-
}
404-
405-
/// Get the `StructDType` if `self` is a `StructDType`, otherwise `None`
439+
/// Owned version of [as_struct_fields_opt].
406440
pub fn into_struct_fields_opt(self) -> Option<StructFields> {
407441
if let Struct(f, _) = self {
408442
Some(f)

0 commit comments

Comments
 (0)