Есть вот такой код и он компилится:
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(dead_code)]
extern crate piston;
extern crate piston_window;
extern crate image as im;
extern crate gfx;
extern crate gfx_device_gl;
extern crate noise;
extern crate rand;
use piston_window::*;
use im::RgbaImage;
use noise::{Brownian2, perlin2};
struct Txtr {
pos: [u32;2],
txtr: Texture<gfx_device_gl::Resources>,
}
struct App {
texture: Txtr,
}
const TSIZE: u32 = 64;
impl App {
fn new( window: &mut PistonWindow ) -> Self {
let seed = rand::random();
let noise = Brownian2::new(perlin2, 4).wavelength(32.0);
let img = im::RgbaImage::from_fn( 64, 64, |x, y| {
let v = noise.apply(&seed, &[ x as f32, y as f32 ]) as f32;
let gray = (128f32 * v + 128f32) as u8;
im::Rgba([ gray, gray, gray, 255])
} );
App{
texture: Txtr{
pos:[0,0],
txtr:Texture::from_image( &mut window.factory, &img, &TextureSettings::new() ).unwrap()
},
}
}
}
fn main() {
let mut window: PistonWindow = WindowSettings::new("Hello World!", (800, 600) ).build().unwrap();
let mut app:App = App::new( &mut window );
}
Однако если мы чуть поменяем его:
struct App {
textures: Vec<Txtr>,
}
const TSIZE: u32 = 64;
impl App {
fn new( window: &mut PistonWindow ) -> Self {
let mut t:Vec<Txtr> = Vec::new();
let seed = rand::random();
let noise = Brownian2::new(perlin2, 4).wavelength(32.0);
for t in 0..3{
let img = im::RgbaImage::from_fn( 64, 64, |x, y| {
let v = noise.apply(&seed, &[ x as f32, y as f32 ]) as f32;
let gray = (128f32 * v + 128f32) as u8;
im::Rgba([ gray, gray, gray, 255])
} );
t.push( Txtr{
pos:[0,0],
txtr:Texture::from_image( &mut window.factory, &img, &TextureSettings::new() ).unwrap()
} );
};
App{
textures: t,
}
}
}
То получаем следующую проблему:
hello3.rs:46:6: 46:10 error: no method named `push` found for type `_` in the current scope
hello3.rs:46 t.push( Txtr{
^~~~
ЯННП, где-то теряется тип или что?