Is there a convenient way to convert a struct<T> (where all fields are of type T) into struct<U> where U: From<T>?

This page summarizes the projects mentioned and recommended in the original post on /r/rust

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • derive_more

    Some more derive(Trait) options

  • This fails to compile. Looking at the implementation for that macro I don't see a way to use it that would work: https://github.com/JelteF/derive_more/blob/master/impl/src/from.rs

  • frunk

    Funktional generic type-level programming in Rust: HList, Coproduct, Generic, LabelledGeneric, Validated, Monoid and friends.

  • I suggest looking into frunk. You could convert the struct into an HList, map over the values to convert and convert into the target struct. README has some relevant examples.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts