Infallible BodyError guidance #505
-
|
When should |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
The type BodyError = <Self::Body as axum::body::HttpBody>::Error;Then rust can infer the error type from the body without you having to specify it. Generally the error type will only be infallible if you're using |
Beta Was this translation helpful? Give feedback.
The
BodyErrorassociated type only exists to makeimpl IntoResponsework, without it you would have to specify the exact body type. As such you cannot pick whatever error type you want. It must always match theBodyassociated type. For example if you're usingaxum::body::Bodythe error must behyper::Errorbecause that how the trait is implemented in hyper. So you should always set it toThen rust can infer the error type from the body without you having to specify it.
Generally the error type will only be infallible if you're using
FullorEmptyas the body type.