It may be silly, but as I learn Rust, the biggest problem for me is to read docs for modules. One of the issues, that I can't construct proper use
path to the object to use it.
Without concrete example it sounds silly, so here it is:
I have a piece of code which uses piston library. The have events iterator which return event, which, according to docs, is a simple enum: piston::event::Event - Rust
I have an event loop, and when I do debug print for events, I see exactly what was promised in docs: Render, PostRender, Idle, etc.
But when I try to do pattern matching on those, I just can't spell the path to things I want to match:
Docs says: piston::event::Event
I tried:
use piston;
...
match e {
piston::event::Event => {println!("here");}
}
and got "could not find event
in piston
".
I've tried to write
use piston::event
but got the same error.
I've tried to break code to see what type it expects:
77 | 1 => {println!("here");},
| ^ expected enum `piston_window::Event`, found integer
I've tried to use this thing, but error is confusing:
77 | piston_window::Event::Render => {println!("here");},
| ^^^^^^ variant or associated item not found in `piston_window::Event`
Docs for piston_window
are different: piston_window::Event - Rust
and it's not the things I see in debug output:
match e {
_ => {println!("{:?}", e);}
}
Example of output is:
Update(UpdateArgs { dt: 0.008333333333333333 })
Idle(IdleArgs { dt: 0.00094002 })
Render(RenderArgs { ext_dt: 0.001123099, window_size: [800.0, 600.0], draw_size: [800, 600] })
AfterRender(AfterRenderArgs)
Idle(IdleArgs { dt: 0.005773664 })
As you can see, it's not the piston_window::Event
, it looks like piston::event::Event
, but I can't use
it.
I'm completely lost. Either I don't know how to interpret docs, or something strange is there...