murar8 / axum_typed_multipart

Type safe multipart/form-data handling for axum.
77 stars 13 forks source link

allow newtype idiom #52

Closed ibotty closed 1 year ago

ibotty commented 1 year ago

When I have e.g.

#[derive(Deserialize, TryFromMultipart)]
struct Form {
  test: MyNewtype,
}

struct MyNewtype(String)

It complains that MyNewtype does not implement TryFromChunks. How can I use a newtype without writing a custom implementation?

murar8 commented 1 year ago

Hi, the derive macro doesn't know how to transform a stream of data to a custom type so implementing TryFromChunks is unavoidable.

murar8 commented 1 year ago

In this case the implementation would be really easy given that you can get the value by using String::TryFromChunks and wrap it.

murar8 commented 1 year ago

For reference: https://docs.rs/axum_typed_multipart/latest/axum_typed_multipart/#custom-types