gpt4 book ai didi

stack-overflow - 任务 'rustc' 已溢出其堆栈

转载 作者:行者123 更新时间:2023-11-29 08:25:45 26 4
gpt4 key购买 nike

无法编译的聊天服务器:

use std::io::{TcpListener, TcpStream};
use std::io::{Acceptor, Listener};

enum StreamOrSlice {
Strm(TcpStream),
Slc(uint, [u8, ..1024])
}

fn main() {
let listener = TcpListener::bind("127.0.0.1", 5555);

// bind the listener to the specified address
let mut acceptor = listener.listen();

let (tx, rx) = channel();

spawn(proc() {
let mut streams: Vec<TcpStream> = Vec::new();
loop {
let rxd: StreamOrSlice = rx.recv();
match rxd {
Strm(stream) => {
streams.push(stream);
}
Slc(len, buf) => {
for stream in streams.iter_mut() {
let _ = stream.write(buf.slice(0, len));
}
}
}
}
});

// accept connections and process them, spawning a new tasks for each one
for stream in acceptor.incoming() {
match stream {
Err(e) => { /* connection failed */ }
Ok(mut stream) => {
// connection succeeded
tx.send(Strm(stream.clone()));
let tx2 = tx.clone();
spawn(proc() {
let mut buf: [u8, ..1024] = [0, ..1024];
loop {
let len = stream.read(buf);
tx2.send(Slc(len.unwrap(), buf));
}
})
}
}
}
}

错误是:

   Compiling chat v0.1.0 (file:///home/chris/rust/chat)
task 'rustc' has overflowed its stack
Could not compile `chat`.

这是否可以在代码中修复,还是编译器错误?

注意:@Levans 感谢您今晚的帮助。

最佳答案

编译器崩溃了。您甚至没有编写自己的宏。这 100% 是一个编译器错误。报告它。

关于stack-overflow - 任务 'rustc' 已溢出其堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26266722/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com