Skip to content

Commit

Permalink
Minor: Allow Field::new to take existing String as well as &str (#3288
Browse files Browse the repository at this point in the history
)
  • Loading branch information
alamb authored Dec 8, 2022
1 parent 99ced48 commit 16484a6
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions arrow-schema/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ impl Hash for Field {

impl Field {
/// Creates a new field
pub fn new(name: &str, data_type: DataType, nullable: bool) -> Self {
pub fn new(name: impl Into<String>, data_type: DataType, nullable: bool) -> Self {
Field {
name: name.to_string(),
name: name.into(),
data_type,
nullable,
dict_id: 0,
Expand All @@ -125,14 +125,14 @@ impl Field {

/// Creates a new field that has additional dictionary information
pub fn new_dict(
name: &str,
name: impl Into<String>,
data_type: DataType,
nullable: bool,
dict_id: i64,
dict_is_ordered: bool,
) -> Self {
Field {
name: name.to_string(),
name: name.into(),
data_type,
nullable,
dict_id,
Expand Down Expand Up @@ -485,6 +485,20 @@ mod test {
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};

#[test]
fn test_new_with_string() {
// Fields should allow owned Strings to support reuse
let s = String::from("c1");
Field::new(s, DataType::Int64, false);
}

#[test]
fn test_new_dict_with_string() {
// Fields should allow owned Strings to support reuse
let s = String::from("c1");
Field::new_dict(s, DataType::Int64, false, 4, false);
}

#[test]
fn test_merge_incompatible_types() {
let mut field = Field::new("c1", DataType::Int64, false);
Expand Down

0 comments on commit 16484a6

Please sign in to comment.