Skip to content

Add impl From<[(K, V); N]> for Metadata so array literals work with with_metadata #10686

Description

@alamb

Is your feature request related to a problem or challenge?

While updating DataFusion to arrow 60 I found that a very common pattern for attaching metadata to a Field or Schema no longer compiles. Before, with_metadata took a HashMap<String, String>, so an array literal converted via type inference:

Field::new("name", DataType::Utf8, false)
    .with_metadata([("some_key".to_string(), "some_value".to_string())].into())

Now that metadata parameters are generic (impl Into<Metadata>), the .into() target can no longer be inferred and this fails with error[E0283]: type annotations needed. The same applies to Default::default() and .collect() in metadata argument position.

Describe the solution you'd like

An array conversion such as:

impl<K: Into<String>, V: Into<String>, const N: usize> From<[(K, V); N]> for Metadata

so callers can pass the array directly, with no .into() and no owned String conversions:

Field::new("name", DataType::Utf8, false).with_metadata([("some_key", "some_value")])

Describe alternatives you've considered

Spelling out the type at each call site, e.g. Metadata::new().with("some_key", "some_value") or HashMap::from([...]); this works but required touching every call site.

Additional context

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAny new improvement worthy of a entry in the changelog

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions