mcarton / rust-derivative

A set of alternative `derive` attributes for Rust
Apache License 2.0
420 stars 46 forks source link

Feature request: Add a way to display only part of a collection-like type #92

Open dzfranklin opened 3 years ago

dzfranklin commented 3 years ago

I want to indicate in the debug representation that a field contains Vec or slice and give a preview of what sort of data it contains without showing the whole slice. I propose an option like so

#[derivative(Debug=take(10))]
field: Vec<u8>

which translates to whatever the debug formatting of the following is

field.iter().take(10).collect::Vec<_>()

I'm happy to make a PR if this is something you're open to.