The #[derive(Into)] macro allows you to extract the values contained within a struct. It does not implement the Into trait directly; instead, it derives From for the contained types, providing an indirect implementation of Into as recommended by Rust documentation.
Single-field structs
For structs with one field, calling .into() returns the inner type.
Multi-field structs
For structs with multiple fields, calling .into() returns a tuple containing the values of those fields.
Customizing conversions with #[into(<types>)]
You can use the #[into(<types>)] attribute on a struct to specify concrete types for the conversions. This is useful for mapping fields to specific types like Cow, String, or specific tuple shapes (e.g., (i64, i64) vs (i32, i32)).
Reference conversions
You can derive conversions into references (mutable or immutable) using #[into(ref(...))] or #[into(ref_mut(...))] within the struct attribute.
Skipping fields
To exclude specific fields from the conversion, use the #[into(skip)] or #[into(ignore)] attribute on the field.
#[derive(Debug, Into, PartialEq)]
struct Int(i32);
assert_eq!(2, Int(2).into());