Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

https://github.com/oxidecomputer/dropshot/compare/v0.16.6\...HEAD[Full list of commits]

* https://github.com/oxidecomputer/dropshot/pull/1520[#1520] Added `From<BodyType>` for `TypedBody<BodyType>` as a constructor

== 0.16.6 (released 2025-12-10)

https://github.com/oxidecomputer/dropshot/compare/v0.16.5\...v0.16.6[Full list of commits]

* https://github.com/oxidecomputer/dropshot/pull/1490[#1490] Added `map` and `try_map` to `Query`, `Path`, `Header`, `HttpResponseOk`, `HttpResponseCreated`, `HttpResponseAccepted`, and `HttpResponseHeaders`, similar to `map` and `try_map` that already exist on `TypedBody`.
* https://github.com/oxidecomputer/dropshot/pull/1490[#1490] Added `map` and `try_map` to `Query`, `Path`, `Header`, `HttpResponseOk`, `HttpResponseCreated`, `HttpResponseAccepted`, and `HttpResponseHeaders`, similar to `map` and `try_map` that already exist on `TypedBody`

== 0.16.5 (released 2025-11-20)

Expand Down
25 changes: 24 additions & 1 deletion dropshot/src/extractor/body.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Oxide Computer Company
// Copyright 2026 Oxide Computer Company

//! Body-related extractor(s)

Expand Down Expand Up @@ -66,6 +66,14 @@ impl<BodyType: JsonSchema + DeserializeOwned + Send + Sync>
}
}

impl<BodyType: JsonSchema + DeserializeOwned + Send + Sync> From<BodyType>
for TypedBody<BodyType>
{
fn from(value: BodyType) -> Self {
TypedBody { inner: value }
}
}

#[derive(Debug)]
pub struct MultipartBody {
pub content: multer::Multipart<'static>,
Expand Down Expand Up @@ -515,4 +523,19 @@ mod tests {

assert!(r.is_ok())
}

#[test]
fn test_typed_body_from() {
#[derive(Deserialize, JsonSchema, Clone, Debug, PartialEq, Eq)]
struct SampleBody {
field: String,
}

let sample = SampleBody { field: "value".to_string() };

let typed_body: crate::extractor::body::TypedBody<SampleBody> =
sample.clone().into();

assert_eq!(typed_body.into_inner(), sample);
}
}