Skip to content

Commit 6a437b5

Browse files
authored
feat: make Canvas::into_map able to generate Pts of any type (#80)
1 parent 2df5bbb commit 6a437b5

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

aoclp/src/mapping/canvas/dynamic.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use std::collections::HashMap;
2+
use std::fmt::Debug;
3+
use std::hash::Hash;
24
use std::iter::{repeat_n, successors};
35
use std::ops::{Index, IndexMut};
46
use std::vec;
@@ -242,7 +244,12 @@ impl<T> Canvas<T> {
242244
/// map,
243245
/// );
244246
/// ```
245-
pub fn into_map(self) -> HashMap<Pt<usize>, T> {
247+
pub fn into_map<PT>(self) -> HashMap<Pt<PT>, T>
248+
where
249+
PT: TryFrom<usize>,
250+
<PT as TryFrom<usize>>::Error: Debug,
251+
Pt<PT>: Copy + Hash + Eq,
252+
{
246253
matrix_to_map(self.0)
247254
}
248255

aoclp/src/mapping/canvas/fixed.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::array;
22
use std::collections::HashMap;
3+
use std::fmt::Debug;
4+
use std::hash::Hash;
35
use std::iter::{repeat_n, successors};
46
use std::ops::{Index, IndexMut};
57

@@ -295,7 +297,12 @@ impl<T, const W: usize, const H: usize> Canvas<T, W, H> {
295297
/// map,
296298
/// );
297299
/// ```
298-
pub fn into_map(self) -> HashMap<Pt<usize>, T> {
300+
pub fn into_map<PT>(self) -> HashMap<Pt<PT>, T>
301+
where
302+
PT: TryFrom<usize>,
303+
<PT as TryFrom<usize>>::Error: Debug,
304+
Pt<PT>: Copy + Hash + Eq,
305+
{
299306
matrix_to_map(self.0)
300307
}
301308
}

0 commit comments

Comments
 (0)