Closed ffred closed 1 year ago
Hey,
I am not sure what exactly you are trying to achieve, but if you want to access a specific row, why don't you just use the grid[x]
function? This will return a row as a slice.
as I said, I did what I needed completely differently, so I got it working.
but I tried yesterday with grid[x]
and since I got an error, I thought it wasn't the right way...
for example, this :
let mut result: Grid<u8> = Grid::new(36,6);
...
println!("{:?}", result[4]);
give me this error :
Compiling tst6 v0.1.0 (K:\dev\rust\tst6)
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> src\main.rs:45:22
|
45 | println!("{:?}", result[4]);
| ^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u8]`
note: required by a bound in `ArgumentV1::<'a>::new_debug`
--> D:\Users\ffred\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\fmt\mod.rs:351:5
|
351 | arg_new!(new_debug, Debug);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ArgumentV1::<'a>::new_debug`
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `arg_new` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
error: could not compile `tst6` due to previous error
* The terminal process "D:\Users\ffred\.cargo\bin\cargo.exe 'run', '--package', 'tst6', '--bin', 'tst6'" terminated with exit code: 101.
* Terminal will be reused by tasks, press any key to close it.
@ffred you could use the to_vec
method to create a vector out of the slice. I guess that would solve your problem. Such as grid[0].to_vec()
. Does this answer your question? For more info on slices have a look here: https://doc.rust-lang.org/book/ch04-03-slices.html
@becheran you're right, it's good. 👍 still have a lot to learn... thank you !!
Hi, still learning Rust, so maybe not really a Grid question but how can I read an entire Row and not cell by cell ? so not
grid[x][y]
, but a way to havegrid.get_row(x)
thanks[Edit:] did what I needed differently by using
pop_row()
.