TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Rust, let me share your awesomeness with C

1 pointsby ttouchover 5 years ago

1 comment

db48xover 5 years ago
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 未加载