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

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Help Net Security
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
D
Docker
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
博客园 - Franky
B
Blog RSS Feed
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
量子位
V
Visual Studio Blog
Y
Y Combinator Blog
小众软件
小众软件
N
Netflix TechBlog - Medium
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security 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.