TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Rust, let me share your awesomeness with C

1 点作者 ttouch超过 5 年前

1 comment

db48x超过 5 年前
That&#x27;s a nice problem. As far as I know, the Rust standard library doesn&#x27;t have a way to create a TcpStream that wraps an existing raw file descriptor. You can only get a raw file descriptor via FFI anyway, so that&#x27;s fine for most programs.<p>A TcpStream is just a struct containing the file descriptor (<a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;blob&#x2F;master&#x2F;src&#x2F;libstd&#x2F;sys_common&#x2F;net.rs#L207-L209" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;blob&#x2F;master&#x2F;src&#x2F;libstd&#x2F;sys...</a>) and nothing else, so this would be fine:<p><pre><code> let stream: std::net::TcpStream = unsafe { std::mem::transmute(socket) };</code></pre>
评论 #22337780 未加载