惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
罗磊的独立博客
博客园 - 聂微东
T
The Blog of Author Tim Ferriss
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
F
Fortinet All Blogs
A
About on SuperTechFans
腾讯CDC
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
IT之家
IT之家
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
宝玉的分享
宝玉的分享
C
Check Point Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
爱范儿
爱范儿
Microsoft Security Blog
Microsoft Security Blog
月光博客
月光博客
T
Tailwind CSS Blog
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog

Leo's Field

Don't nuke my docker network, nftables.service! - Leo's Field Sending Emails, with netcat - Leo's Field Use ZED with msmtp on Debian - Leo's Field Have fun with ZFS: Maintenance and Error Recovery - Leo's Field Have fun with ZFS: Tuning - Leo's Field Have fun with ZFS: Setting up storage pool - Leo's Field 2021 Recap: Seek - Leo's Field Deploying this site on CloudFlare Pages - Leo's Field Redesigning this blog - Leo's Field Homelab Project: 6 months in - Leo's Field A Breif Look at Linux's Audio System - Leo's Field Record to MiniDisc with correct Track Marker on Linux - Leo's Field Build Fcitx5 IM module for proprietary software with its Qt library - Leo's Field Way to AOSC OS Maintainer: Advanced Techniques - Leo's Field Way to AOSC OS Maintainer: Basics - Leo's Field Have fun with ZFS: Introduction - Leo's Field Fix clipboard permission on Android 10 - Leo's Field MDR-7506 Detachable Cable Mod - Leo's Field Update firmware of a Crucial SSD with systemd-boot - Leo's Field Install Arch Linux, using a Sony Walkman - Leo's Field Coreboot, me_cleaner, Tianocore, ThinkPad X220 - Leo's Field Dark mode! - Leo's Field Links - Leo's Field Some notes about the creation of this blog - Leo's Field Hello, world! - Leo's Field About - Leo's Field
Fix incompatible bytes library for actix-web and tokio - ...
Leo Shen · 2020-12-29 · via Leo's Field

More Posts 暂无翻译版本

A rare cenario Cargo can't fix it for us.

When attemping to build some web app with actix-web, I ran into this issue:

1
2
3
4
5
6
7
8
error[E0271]: type mismatch resolving `<fn(bytes::BytesMut) -> bytes::Bytes {bytes::BytesMut::freeze} as FnOnce<(bytes::BytesMut,)>>::Output == actix_web::web::Bytes`
  --> src/api/get.rs:35:47
   |
35 |                     return HttpResponse::Ok().streaming(s);
   |                                               ^^^^^^^^^ expected struct `bytes::Bytes`, found struct `actix_web::web::Bytes`
   |
   = note: perhaps two different versions of crate `bytes` are being used?
   = note: required because of the requirements on the impl of `futures_util::fns::FnOnce1<bytes::BytesMut>` for `fn(bytes::BytesMut) -> bytes::Bytes {bytes::BytesMut::freeze}`

This happens when I'm trying to utilize FramedRead in Tokio in order to stream the content while sending it in acitx-web (instead of reading them all into memory before sending it out). As it turned out, this is due to a mismatch in version of the crate bytes.

As the time of this writing, the latest version for actix-web is 3.3.2, and the latest version for tokio is 1.0. Naturally, I add the latest version of both in Cargo.toml. However, since tokio 1.0 is released after actix-web 3.3.2, actix-web is still using an older version of tokio, resulting an older version of bytes. So, sadly there's a mismatch between the bytes crate used in the two components, and it happens to be the case that these two version are not compatible, and thus such error appears.

Fixing this issue is trivial. Simply use a matching version of tokio (here, it should be tokio 0.2.23). cargo tree | grep -z $CRATE is very useful here.