You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We wants to implement the from trait for the BitBoard structure starting from Vec<Cell> to be able to write code like this:
let bb1 = BitBoard::from([Cell::D1,Cell::D2]);let bb2 = BitBoard::from(&[Cell::A1,Cell::H8]);
A possible implementaion is for example the following one (info on this reddit post):
/// From trait for the BitBoard struct starting from a slice of [Cell]s.////// Converts a slice of cells to a [BitBoard] with all the cells of the slice set to busy (1) status.////// # Arguments////// * `cells` - A [Cell] slice with the cells to be set on the [BitBoard]/// # Example///```/// # use abbadingo::bitboard::*;/// # use abbadingo::bbdefines::*;/// let mut bb = BitBoard::new();/// bb.set_file(File::FileD);/// assert_eq!(bb, BitBoard::from([Cell::D1, Cell::D2, Cell::D3, Cell::D4,/// Cell::D5, Cell::D6, Cell::D7, Cell::D8]));///```impl<'a,T:AsRef<[Cell]>>From<T>forBitBoard{fnfrom(cells:T) -> Self{letmut bb = BitBoard::new();for c in cells.as_ref().to_vec(){
bb.set_cell(c);}
bb
}}
The problem is that the above code is not compatible with the From<BitBoardState> trait and with other hypotetical From traits like for example From<Cell>. The issue seems due to the problem of "Trait Specialization"
We wants to implement the
from
trait for theBitBoard
structure starting fromVec<Cell>
to be able to write code like this:A possible implementaion is for example the following one (info on this reddit post):
The problem is that the above code is not compatible with the
From<BitBoardState>
trait and with other hypoteticalFrom
traits like for exampleFrom<Cell>
. The issue seems due to the problem of "Trait Specialization"See also: https://users.rust-lang.org/t/generic-trait-and-specialization/33745
The text was updated successfully, but these errors were encountered: