Skip to content

Commit c815d4f

Browse files
committed
Fix Dictionary iterator and ProcBoolMethod ext
1 parent 0253c72 commit c815d4f

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

src/ext.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ pub use list_1_ext::*;
7171

7272
#[cfg(feature = "system-collections-generic-dictionary_2")]
7373
mod dictionary_2_ext {
74-
use crate::system::collections::generic::dictionary_2::{Dictionary_2, IDictionary_2Methods};
74+
use crate::system::collections::generic::dictionary_2::{
75+
Dictionary_2, IDictionary_2Methods, IDictionary_2_KeyCollectionMethods,
76+
IDictionary_2_ValueCollectionMethods,
77+
};
78+
use ::unity2::Array;
7579

7680
pub trait Dictionary_2Ext<K: Copy + ::unity2::ClassIdentity, V: Copy + ::unity2::ClassIdentity>
7781
{
@@ -83,8 +87,14 @@ mod dictionary_2_ext {
8387
{
8488
fn iter(self) -> Dictionary_2Iter<K, V> {
8589
let len = self.get_count();
90+
let keys = Array::<K>::of_len(len as usize).expect("Dictionary_2Iter: keys alloc");
91+
let values =
92+
Array::<V>::of_len(len as usize).expect("Dictionary_2Iter: values alloc");
93+
self.get_keys().copy_to(keys, 0);
94+
self.get_values().copy_to(values, 0);
8695
Dictionary_2Iter {
87-
dict: self,
96+
keys,
97+
values,
8898
index: 0,
8999
len,
90100
}
@@ -95,7 +105,8 @@ mod dictionary_2_ext {
95105
K: Copy + ::unity2::ClassIdentity,
96106
V: Copy + ::unity2::ClassIdentity,
97107
> {
98-
dict: Dictionary_2<K, V>,
108+
keys: Array<K>,
109+
values: Array<V>,
99110
index: i32,
100111
len: i32,
101112
}
@@ -106,10 +117,25 @@ mod dictionary_2_ext {
106117
type Item = (K, V);
107118

108119
fn next(&mut self) -> Option<(K, V)> {
109-
let _ = (self.index, self.len, self.dict);
110-
None
120+
if self.index >= self.len {
121+
return None;
122+
}
123+
let i = self.index as usize;
124+
let pair = (self.keys.get(i), self.values.get(i));
125+
self.index += 1;
126+
Some(pair)
127+
}
128+
129+
fn size_hint(&self) -> (usize, Option<usize>) {
130+
let r = (self.len - self.index) as usize;
131+
(r, Some(r))
111132
}
112133
}
134+
135+
impl<K: Copy + ::unity2::ClassIdentity, V: Copy + ::unity2::ClassIdentity> ExactSizeIterator
136+
for Dictionary_2Iter<K, V>
137+
{
138+
}
113139
}
114140
#[cfg(feature = "system-collections-generic-dictionary_2")]
115141
pub use dictionary_2_ext::*;
@@ -378,16 +404,16 @@ mod proc_bool_method_ext {
378404
use unity2::{FromIlInstance, IlInstance, OptionalMethod};
379405

380406
pub trait ProcBoolMethodExt: Sized {
381-
fn from_fn(
407+
fn from_fn<T: crate::app::procinst::IProcInst>(
382408
target: IlInstance,
383-
callback: extern "C" fn(IlInstance, OptionalMethod) -> bool,
409+
callback: extern "C" fn(T, OptionalMethod) -> bool,
384410
) -> Option<Self>;
385411
}
386412

387413
impl ProcBoolMethodExt for ProcBoolMethod {
388-
fn from_fn(
414+
fn from_fn<T: crate::app::procinst::IProcInst>(
389415
target: IlInstance,
390-
callback: extern "C" fn(IlInstance, OptionalMethod) -> bool,
416+
callback: extern "C" fn(T, OptionalMethod) -> bool,
391417
) -> Option<Self> {
392418
let intptr = super::method_info_intptr(callback as *mut u8, 0);
393419
Some(ProcBoolMethod::new(

0 commit comments

Comments
 (0)