@@ -116,6 +116,18 @@ impl Type {
116116 matches ! ( self , Type :: Struct ( _) )
117117 }
118118
119+ /// Whether the type is list type.
120+ #[ inline( always) ]
121+ pub fn is_list ( & self ) -> bool {
122+ matches ! ( self , Type :: List ( _) )
123+ }
124+
125+ /// Whether the type is map type.
126+ #[ inline( always) ]
127+ pub fn is_map ( & self ) -> bool {
128+ matches ! ( self , Type :: Map ( _) )
129+ }
130+
119131 /// Whether the type is nested type.
120132 #[ inline( always) ]
121133 pub fn is_nested ( & self ) -> bool {
@@ -160,7 +172,7 @@ impl Type {
160172 Ok ( REQUIRED_LENGTH [ precision as usize - 1 ] )
161173 }
162174
163- /// Creates decimal type.
175+ /// Creates decimal type.
164176 #[ inline( always) ]
165177 pub fn decimal ( precision : u32 , scale : u32 ) -> Result < Self > {
166178 ensure_data_valid ! (
@@ -634,6 +646,16 @@ impl NestedField {
634646 Self :: new ( id, LIST_FIELD_NAME , field_type, required)
635647 }
636648
649+ /// Construct required list type's element field.
650+ pub fn list_required_element ( id : i32 , field_type : Type ) -> Self {
651+ Self :: list_element ( id, field_type, true )
652+ }
653+
654+ /// Construct optional list type's element field.
655+ pub fn list_optional_element ( id : i32 , field_type : Type ) -> Self {
656+ Self :: list_element ( id, field_type, false )
657+ }
658+
637659 /// Construct map type's key field.
638660 pub fn map_key_element ( id : i32 , field_type : Type ) -> Self {
639661 Self :: required ( id, MAP_KEY_FIELD_NAME , field_type)
@@ -667,6 +689,18 @@ impl NestedField {
667689 self . id = id;
668690 self
669691 }
692+
693+ /// Set the type of the field
694+ pub ( crate ) fn of_type ( mut self , field_type : Box < Type > ) -> Self {
695+ self . field_type = field_type;
696+ self
697+ }
698+
699+ /// Set the name of the field.
700+ pub ( crate ) fn with_name ( mut self , name : impl ToString ) -> Self {
701+ self . name = name. to_string ( ) ;
702+ self
703+ }
670704}
671705
672706impl fmt:: Display for NestedField {
@@ -699,6 +733,20 @@ impl ListType {
699733 pub fn new ( element_field : NestedFieldRef ) -> Self {
700734 Self { element_field }
701735 }
736+
737+ /// Construct an optional list type with the given element field.
738+ pub fn optional ( element_id : i32 , element_type : Type ) -> Self {
739+ Self {
740+ element_field : NestedField :: list_element ( element_id, element_type, false ) . into ( ) ,
741+ }
742+ }
743+
744+ /// Construct a required list type with the given element field.
745+ pub fn required ( element_id : i32 , element_type : Type ) -> Self {
746+ Self {
747+ element_field : NestedField :: list_element ( element_id, element_type, true ) . into ( ) ,
748+ }
749+ }
702750}
703751
704752/// Module for type serialization/deserialization.
0 commit comments