murar8 / axum_typed_multipart

Type safe multipart/form-data handling for axum.
84 stars 14 forks source link

How to implement TryFromChunks for external types? #44

Closed selfhoster1312 closed 1 year ago

selfhoster1312 commented 1 year ago

I'm trying to parse a Multipart form into a struct that contains fields that are not defined in my crate, so i can't implement TryFromChunks for them. However they do implement FromStr, but implementing TryFromChunks for any types that implements FromStr would create implementation conflicts for most types...

These types also implement Deserialize. Maybe using serde::Deserialize instead of TryFromChunks could be an option (eg. behind a feature flag)?

nerodono commented 1 year ago

Currently serde doesn't support asynchronous parsing (e.g. you can't make the from_reader function async), so all purpose of the TryFromMultipart/TryFromChunks and so on is to make parsing asynchronous. Possibly there's another issue with that, so cc @murar8

murar8 commented 1 year ago

Implementing the trait for external types directly is not possible AFAIK, we would need specialization to land on stable and it will be a long while if it ever does: https://github.com/rust-lang/rust/issues/31844

In the meanwhile your options are:

murar8 commented 1 year ago

Currently serde doesn't support asynchronous parsing (e.g. you can't make the from_reader function async), so all purpose of the TryFromMultipart/TryFromChunks and so on is to make parsing asynchronous. Possibly there's another issue with that, so cc @murar8

Yeah I don't even know if it would be possible to hack in a blanket implementation for any item that is deserializable so that's definitely a no-go in my opinion.

pascalporedda commented 1 year ago

Which types / external crates would you consider implementing the trait for?

I'd love if uuid and chrono would be supported

murar8 commented 1 year ago

Sure I will look into it :+1:

murar8 commented 1 year ago

Tracked in #46