The trait bound is not satisfied in Rust

后端 未结 1 386
时光取名叫无心
时光取名叫无心 2021-01-13 19:14

I\'m trying to write a Tic Tac Toe game in Rust, but this function for changing a field doesn\'t work and I don\'t know what\'s wrong with it:

fn change_fie         


        
1条回答
  •  孤街浪徒
    2021-01-13 19:30

    The reason is given to you in the notes:

    note: slice indices are of type `usize`
    
    slice indices are of type `usize` or ranges of `usize`
    

    You need to cast the i32 value to usize, for example:

    table[(field - 1) as usize]
    

    Alternatively, consider using usize as the type of the field variable, if it makes sense in your application.

    0 讨论(0)
提交回复
热议问题