Skip to content

Commit 2b3f924

Browse files
committed
chore: release 0.0.16
1 parent 44ad3de commit 2b3f924

File tree

6 files changed

+19
-30
lines changed

6 files changed

+19
-30
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "axum-codec"
3-
version = "0.0.15"
3+
version = "0.0.16"
44
edition = "2021"
55
description = "A multi-codec extractor and response writer for Axum"
66
license = "MIT OR Apache-2.0"
@@ -16,7 +16,7 @@ members = ["macros", ".", "examples/*"]
1616
[dependencies]
1717
aide = { version = "0.13", optional = true, default-features = false, features = ["axum"] }
1818
axum = { version = "0.7", default-features = false }
19-
axum-codec-macros = { path = "macros", version = "0.0.11", default-features = false }
19+
axum-codec-macros = { path = "macros", version = "0.0.12", default-features = false }
2020
bincode = { version = "2.0.0-rc.3", default-features = false, features = ["std"], optional = true }
2121
# 0.6.3 added the #[bitcode(crate = "...")] option
2222
bitcode = { version = "0.6.3", default-features = false, features = ["std"], optional = true }

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,7 @@ A body extractor for the [Axum](https://github.com/tokio-rs/axum) web framework.
1111
- Supports encoding and decoding of various formats with a single extractor.
1212
- Provides a wrapper for [`axum::routing::method_routing`](https://docs.rs/axum/latest/axum/routing/method_routing/index.html) to automatically encode responses in the correct format according to the specified `Accept` header (with a fallback to `Content-Type`, then one of the enabled formats).
1313
- Provides an attribute macro (under the `macros` feature) to add derives for all enabled formats to a struct/enum.
14-
15-
## Todo
16-
17-
- [x] Support `bitcode`, `bincode`, `ciborium`, `rmp`, `toml`, `serde_yaml`, and `serde_json`
18-
- [x] Add custom `MethodRouter` to automatically encode responses in the correct format
19-
- [x] Add macro to derive all enabled formats for a struct/enum
20-
- [x] Add support for [`aide`](https://github.com/tamasfe/aide)
21-
- [x] Add support for [`validator`](https://github.com/Keats/validator)
22-
- [ ] Support more formats (issues and PRs welcome)
23-
- [ ] Add benchmarks?
14+
- Zero-copy decoding with `BorrowCodec`.
2415

2516
Here's a quick example that can do the following:
2617

examples/basic/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async fn borrow_greet(greeting: BorrowCodec<BorrowGreeting<'_>>) -> impl IntoCod
5353
"Message is borrowed".into()
5454
} else {
5555
"Message is owned".into()
56-
}
56+
},
5757
})
5858
}
5959

macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "axum-codec-macros"
3-
version = "0.0.11"
3+
version = "0.0.12"
44
edition = "2021"
55
description = "Procedural macros for axum-codec"
66
license = "MIT OR Apache-2.0"

src/extract.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -302,19 +302,16 @@ where
302302
/// See [`CodecRejection`] for more information.
303303
pub fn from_bytes(bytes: BytesMut, content_type: ContentType) -> Result<Self, CodecRejection> {
304304
let data = Codec::<T>::from_bytes(
305-
// SAFETY: The bytes that are being referenced by the slice are behind a pointer
306-
// so they will not move. The bytes are also kept alive by the struct that contains
307-
// this struct that references the slice, so the bytes will not be deallocated
308-
// while this struct is alive.
309-
unsafe { std::slice::from_raw_parts(bytes.as_ptr(), bytes.len()) },
310-
content_type,
311-
)?
312-
.into_inner();
313-
314-
Ok(Self {
315-
data,
316-
bytes,
317-
})
305+
// SAFETY: The bytes that are being referenced by the slice are behind a pointer
306+
// so they will not move. The bytes are also kept alive by the struct that contains
307+
// this struct that references the slice, so the bytes will not be deallocated
308+
// while this struct is alive.
309+
unsafe { std::slice::from_raw_parts(bytes.as_ptr(), bytes.len()) },
310+
content_type,
311+
)?
312+
.into_inner();
313+
314+
Ok(Self { data, bytes })
318315
}
319316
}
320317

@@ -424,7 +421,8 @@ mod miri {
424421
fn test_zero_copy() {
425422
let bytes = b"{\"hello\": \"world\"}".to_vec();
426423
let data =
427-
BorrowCodec::<BorrowData>::from_bytes(BytesMut::from(Bytes::from(bytes)), ContentType::Json).unwrap();
424+
BorrowCodec::<BorrowData>::from_bytes(BytesMut::from(Bytes::from(bytes)), ContentType::Json)
425+
.unwrap();
428426

429427
assert_eq!(data.hello, Cow::Borrowed("world"));
430428
}

0 commit comments

Comments
 (0)