Skip to content

Commit 66447cb

Browse files
committed
Fix docs and doc tests
1 parent 19e1571 commit 66447cb

File tree

5 files changed

+60
-24
lines changed

5 files changed

+60
-24
lines changed

borsh/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ async-std = { version = "1", default-features = false, features = ["std"], optio
4747

4848
[dev-dependencies]
4949
tokio-test = "0.4.4"
50+
tokio = { version = "1", features = ["io-std"] }
5051
insta = "1.29.0"
5152
serde_json = { version = "1" }
5253

borsh/docs/rustdoc_include/borsh_crate_top_level.md

+2
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,6 @@ Following pages are highlighted here just to give reader a chance at learning th
8585
- [Derive Macro `BorshSerialize`](macro@crate::BorshSerialize)
8686
- [Derive Macro `BorshDeserialize`](macro@crate::BorshDeserialize)
8787
- [Derive Macro `BorshSchema`](macro@crate::BorshSchema)
88+
- [Derive Macro `BorshSerializeAsync`](macro@crate::BorshSerializeAsync)
89+
- [Derive Macro `BorshDeserializeAsync`](macro@crate::BorshDeserializeAsync)
8890

borsh/src/de/mod.rs

+44-20
Original file line numberDiff line numberDiff line change
@@ -1632,27 +1632,51 @@ pub fn from_slice<T: BorshDeserialize>(v: &[u8]) -> Result<T> {
16321632

16331633
/// Deserializes an object from a reader.
16341634
/// # Example
1635-
/// ```
1636-
/// use borsh::{BorshDeserialize, BorshSerialize, from_reader, to_vec};
1637-
///
1638-
/// /// derive is only available if borsh is built with `features = ["derive"]`
1639-
/// # #[cfg(feature = "derive")]
1640-
/// #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)]
1641-
/// struct MyStruct {
1642-
/// a: u64,
1643-
/// b: Vec<u8>,
1644-
/// }
1645-
///
1646-
/// # #[cfg(feature = "derive")]
1647-
/// let original = MyStruct { a: 10, b: vec![1, 2, 3] };
1648-
/// # #[cfg(feature = "derive")]
1649-
/// let encoded = to_vec(&original).unwrap();
1650-
/// # #[cfg(feature = "derive")]
1651-
/// let decoded = from_reader::<_, MyStruct>(&mut encoded.as_slice()).unwrap();
1652-
/// # #[cfg(feature = "derive")]
1653-
/// assert_eq!(original, decoded);
1654-
/// ```
16551635
#[async_generic(
1636+
/// ```
1637+
/// use borsh::{BorshDeserialize, BorshSerialize, from_reader, to_vec};
1638+
///
1639+
/// /// derive is only available if borsh is built with `features = ["derive"]`
1640+
/// # #[cfg(feature = "derive")]
1641+
/// #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)]
1642+
/// struct MyStruct {
1643+
/// a: u64,
1644+
/// b: Vec<u8>,
1645+
/// }
1646+
///
1647+
/// # #[cfg(feature = "derive")]
1648+
/// let original = MyStruct { a: 10, b: vec![1, 2, 3] };
1649+
/// # #[cfg(feature = "derive")]
1650+
/// let encoded = to_vec(&original).unwrap();
1651+
/// # #[cfg(feature = "derive")]
1652+
/// let decoded = from_reader::<_, MyStruct>(&mut encoded.as_slice()).unwrap();
1653+
/// # #[cfg(feature = "derive")]
1654+
/// assert_eq!(original, decoded);
1655+
/// ```
1656+
sync_signature;
1657+
1658+
/// ```
1659+
/// use borsh::{BorshDeserializeAsync, BorshSerialize, from_reader_async, to_vec};
1660+
///
1661+
/// /// derive is only available if borsh is built with `features = ["derive"]`
1662+
/// # #[cfg(feature = "derive")]
1663+
/// #[derive(BorshSerialize, BorshDeserializeAsync, PartialEq, Debug)]
1664+
/// struct MyStruct {
1665+
/// a: u64,
1666+
/// b: Vec<u8>,
1667+
/// }
1668+
///
1669+
/// # tokio_test::block_on(async {
1670+
/// # #[cfg(feature = "derive")]
1671+
/// let original = MyStruct { a: 10, b: vec![1, 2, 3] };
1672+
/// # #[cfg(feature = "derive")]
1673+
/// let encoded = to_vec(&original).unwrap();
1674+
/// # #[cfg(feature = "derive")]
1675+
/// let decoded = from_reader_async::<_, MyStruct>(&mut encoded.as_slice()).await.unwrap();
1676+
/// # #[cfg(feature = "derive")]
1677+
/// assert_eq!(original, decoded);
1678+
/// # });
1679+
/// ```
16561680
#[cfg(feature = "unstable__async")]
16571681
async_signature[impl_fut]<R: AsyncRead, T: BorshDeserializeAsync>(
16581682
reader: &mut R,

borsh/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ compile_error!(
5858
#[cfg(feature = "std")]
5959
use std::io as io_impl;
6060

61-
/// Module is available if `borsh` is built with `features = ["unstable__async"]`.
62-
///
6361
/// Provides traits for async I/O operations.
62+
///
63+
/// Module is available if `borsh` is built with `features = ["unstable__async"]`.
6464
#[cfg(feature = "unstable__async")]
6565
pub mod async_io;
6666

borsh/src/ser/helpers.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,25 @@ where
2626
}
2727

2828
/// Serializes an object directly into a `Writer`.
29-
/// # Example
3029
///
30+
/// # Example
3131
#[async_generic(
3232
/// ```
3333
/// # #[cfg(feature = "std")]
3434
/// let stderr = std::io::stderr();
3535
/// # #[cfg(feature = "std")]
36-
/// assert_eq!((), borsh::to_writer(&stderr, "hello_0x0a").unwrap());
36+
/// borsh::to_writer(&stderr, "hello_0x0a").unwrap();
3737
/// ```
3838
sync_signature;
39+
40+
/// ```
41+
/// # tokio_test::block_on(async {
42+
/// # #[cfg(feature = "unstable__tokio")]
43+
/// let mut stderr = tokio::io::stderr();
44+
/// # #[cfg(feature = "unstable__tokio")]
45+
/// borsh::to_writer_async(&mut stderr, "hello_0x0a").await.unwrap();
46+
/// # })
47+
/// ```
3948
#[cfg(feature = "unstable__async")]
4049
async_signature<T, W: AsyncWrite>(mut writer: W, value: &T) -> Result<()>
4150
where

0 commit comments

Comments
 (0)