-
-
Notifications
You must be signed in to change notification settings - Fork 873
Description
I'm designing an http api where every response is json and has diffferent fields depending on the api call, but always has a status and code field. I am acomplishing this through the Response struct:
#[derive(Debug, Serialize)]
pub struct Response<T> {
#[serde(flatten)]
data: T,
status: Status,
}In situations where I just want to return a status, I intended on constructing a Response<()>, but that gives me this error:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("can only flatten structs and maps (got unit)", line: 0, column: 0)', src/libcore/result.rs:1189:5
I expected that flattening a Unit would just add no fields. I could make a struct with no fields and make a Response<NoFields>, but that seems unidiomatic and requires adding an extra type that doesn't do anything. Is there a reason that you can't flatten a Unit?