Skip to content

Commit

Permalink
add tokio bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
pymongo committed Jun 8, 2024
1 parent c770950 commit 496c948
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 2024/06/tokio_bytes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# [Bytes和Vec<u8>唯一不同](/2024/06/tokio_bytes.md)

为了收到错误的业务状态码响应的时候打印下请求的body,但.body()方法会move掉String

为了减少一次clone,引发我对reqwest body(Bytes)源码阅读

由于只有static的引用才能在async rust中共享,不得不都把引用包层Arc这样有所有权可以move进异步闭包

我注意到reqwest body可以传入Bytes 克隆一次Bytes后面请求后就能打印请求body的Bytes了

此外gpt说Bytes还有一个不同就是不会像Vec push/pop发生内存变化,但不可变的`Vec<u8>`从栈上变量push到另一个二维数组上应该也没事

我之前写过相关的文章 [Vec 动态扩容悬垂裸指针](/2023/08/vec_push_mem_addr_change_cause_ffi_fail.md)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- [文章列表 - 吴翱翔的博客](/)
- [正在读的书](/books.md)
- **2024-06**
- [Bytes和Vec<u8>唯一不同](/2024/06/tokio_bytes.md)
- [订单不平衡因子过拟合](/2024/06/order_imbalance_factor.md)
- [DEX土狗战法](/2024/06/dex_and_meme_coin.md)
- [asyncio diff loop](/2024/06/python3_asyncio_future_attach_to_a_different_loop.md)
Expand Down

0 comments on commit 496c948

Please sign in to comment.