如何返回在rust中保存引用的结构?

时间:2018-07-25 16:30:37

标签: rust lifetime noise

这可能是非常愚蠢的事情,但是我正在尝试编写一个返回此结构的函数:https://docs.rs/noise/0.5.1/noise/struct.Curve.html

pub struct Curve<'a, T: 'a> {
  pub source: &'a NoiseFn<T>,
  // some fields omitted
}

在函数中,我正在实例化此结构:https://docs.rs/noise/0.5.1/noise/struct.Fbm.html

pub struct Fbm {
    pub octaves: usize,
    pub frequency: f64,
    pub lacunarity: f64,
    pub persistence: f64,
    // some fields omitted
}

这是我的代码:

extern crate noise;
use noise::{Fbm, Curve}

fn generate_continent() -> ?? {
    let fb0 = Fbm::new();
    let fb0_cu = Curve::new(&fb0);
    fb0_cu
}

尽管我在new()之后将一些方法链接到Fbm和Curve,但这实际上是我要尝试的方法。函数签名是什么?

如果我只返回Curve,就会收到此错误:

error[E0106]: missing lifetime specifier
--> src/planet_noise.rs:25:33
 |
25 | pub fn generate_continents() -> Curve  {
 |                                 ^^^^^ expected lifetime parameter
 |
 = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
 = help: consider giving it a 'static lifetime

0 个答案:

没有答案