Skip to content

Commit bb3e520

Browse files
committed
feat: into_struct_fields_*
I find myself wanting this in Spiral. Is it reasonable? Signed-off-by: Daniel King <[email protected]>
1 parent 8945cd8 commit bb3e520

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

vortex-dtype/src/dtype.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,27 @@ impl DType {
390390
}
391391
}
392392

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`
406+
pub fn into_struct_fields_opt(self) -> StructFields {
407+
if let Struct(f, _) = self {
408+
Some(f)
409+
} else {
410+
None
411+
}
412+
}
413+
393414
/// Convenience method for creating a [`DType::List`].
394415
pub fn list(dtype: impl Into<DType>, nullability: Nullability) -> Self {
395416
List(Arc::new(dtype.into()), nullability)

0 commit comments

Comments
 (0)