实现具有生命周期的结构
Implementing struct that has lifetimes
这是我的代码:
struct Server<'a> {
port: &'a u16,
}
impl Server {
fn connect() {
//stuff
}
}
我得到的错误是 impl
块:
error: wrong number of lifetime parameters: expected 1, found 0 [E0107]
我必须向 Server
添加生命周期参数以允许 u16
切片,但我不知道如何为 impl
块添加生命周期参数。
您还需要在实现上添加生命周期注释。
impl<'a> Server<'a> {
fn connect() {
//stuff
}
}
这是我的代码:
struct Server<'a> {
port: &'a u16,
}
impl Server {
fn connect() {
//stuff
}
}
我得到的错误是 impl
块:
error: wrong number of lifetime parameters: expected 1, found 0 [E0107]
我必须向 Server
添加生命周期参数以允许 u16
切片,但我不知道如何为 impl
块添加生命周期参数。
您还需要在实现上添加生命周期注释。
impl<'a> Server<'a> {
fn connect() {
//stuff
}
}