arrow_udf_js/into_field.rs
1// Copyright 2024 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use arrow_schema::{DataType, Field};
16
17/// Converts a type into a [`Field`].
18/// Implementors are [`DataType`] and [`Field`].
19pub trait IntoField: private::Sealed {
20 fn into_field(self, default_name: &str) -> Field;
21}
22
23impl IntoField for Field {
24 fn into_field(self, _default_name: &str) -> Field {
25 self
26 }
27}
28
29impl IntoField for DataType {
30 fn into_field(self, default_name: &str) -> Field {
31 Field::new(default_name, self, true)
32 }
33}
34
35mod private {
36 use arrow_schema::{DataType, Field};
37
38 pub trait Sealed {}
39 impl Sealed for Field {}
40 impl Sealed for DataType {}
41}