diff --git a/demo/rust/src/implementation/file_system_tree.rs b/demo/rust/src/implementation/file_system_tree.rs index a2116a4..4c078fd 100644 --- a/demo/rust/src/implementation/file_system_tree.rs +++ b/demo/rust/src/implementation/file_system_tree.rs @@ -149,13 +149,13 @@ where } self.model.end_reset_model(); } - fn get(&self, item: usize) -> &Entry { - &self.entries[item] + fn get(&self, index: usize) -> &Entry { + &self.entries[index] } - fn retrieve(&mut self, item: usize) { - let parents = self.get_parents(item); + fn retrieve(&mut self, index: usize) { + let parents = self.get_parents(index); let incoming = self.incoming.clone(); - T::retrieve(item, parents, incoming, self.emit.clone()); + T::retrieve(index, parents, incoming, self.emit.clone()); } fn process_incoming(&mut self) { if let Ok(ref mut incoming) = self.incoming.try_lock() { @@ -231,35 +231,35 @@ where self.reset(); } } - fn can_fetch_more(&self, item: Option) -> bool { - if let Some(item) = item { - let entry = self.get(item); + fn can_fetch_more(&self, index: Option) -> bool { + if let Some(index) = index { + let entry = self.get(index); entry.children.is_none() && entry.data.can_fetch_more() } else { false } } - fn fetch_more(&mut self, item: Option) { + fn fetch_more(&mut self, index: Option) { self.process_incoming(); - if !self.can_fetch_more(item) { + if !self.can_fetch_more(index) { return; } - if let Some(item) = item { - self.retrieve(item); + if let Some(index) = index { + self.retrieve(index); } } - fn row_count(&self, item: Option) -> usize { + fn row_count(&self, index: Option) -> usize { if self.entries.is_empty() { return 0; } - if let Some(i) = item { + if let Some(i) = index { let entry = self.get(i); if let Some(ref children) = entry.children { children.len() } else { // model does lazy loading, signal that data may be available - if self.can_fetch_more(item) { - self.emit.new_data_ready(item); + if self.can_fetch_more(index) { + self.emit.new_data_ready(index); } 0 } @@ -267,36 +267,36 @@ where 1 } } - fn index(&self, item: Option, row: usize) -> usize { - if let Some(item) = item { - self.get(item).children.as_ref().unwrap()[row] + fn index(&self, index: Option, row: usize) -> usize { + if let Some(index) = index { + self.get(index).children.as_ref().unwrap()[row] } else { 0 } } - fn parent(&self, item: usize) -> Option { - self.entries[item].parent + fn parent(&self, index: usize) -> Option { + self.entries[index].parent } - fn row(&self, item: usize) -> usize { - self.entries[item].row + fn row(&self, index: usize) -> usize { + self.entries[index].row } - fn file_name(&self, item: usize) -> String { - self.get(item).data.file_name() + fn file_name(&self, index: usize) -> String { + self.get(index).data.file_name() } - fn file_permissions(&self, item: usize) -> i32 { - self.get(item).data.file_permissions() + fn file_permissions(&self, index: usize) -> i32 { + self.get(index).data.file_permissions() } #[allow(unused_variables)] - fn file_icon(&self, item: usize) -> &[u8] { - self.get(item).data.icon() + fn file_icon(&self, index: usize) -> &[u8] { + self.get(index).data.icon() } - fn file_path(&self, item: usize) -> Option { - self.get(item).data.file_path() + fn file_path(&self, index: usize) -> Option { + self.get(index).data.file_path() } - fn file_type(&self, item: usize) -> i32 { - self.get(item).data.file_type() + fn file_type(&self, index: usize) -> i32 { + self.get(index).data.file_type() } - fn file_size(&self, item: usize) -> Option { - self.get(item).data.file_size() + fn file_size(&self, index: usize) -> Option { + self.get(index).data.file_size() } } diff --git a/demo/rust/src/implementation/processes.rs b/demo/rust/src/implementation/processes.rs index 7d4a188..f975963 100644 --- a/demo/rust/src/implementation/processes.rs +++ b/demo/rust/src/implementation/processes.rs @@ -153,12 +153,12 @@ fn update_thread( } impl Processes { - fn get(&self, item: usize) -> &ProcessItem { - let pid = item as pid_t; + fn get(&self, index: usize) -> &ProcessItem { + let pid = index as pid_t; &self.p.processes[&pid] } - fn process(&self, item: usize) -> &Process { - let pid = item as pid_t; + fn process(&self, index: usize) -> &Process { + let pid = index as pid_t; &self.p.processes[&pid].process } } @@ -337,25 +337,25 @@ impl ProcessesTrait for Processes { fn emit(&self) -> &ProcessesEmitter { &self.emit } - fn row_count(&self, item: Option) -> usize { - if let Some(item) = item { - self.get(item).tasks.len() + fn row_count(&self, index: Option) -> usize { + if let Some(index) = index { + self.get(index).tasks.len() } else { self.p.top.len() } } - fn index(&self, item: Option, row: usize) -> usize { - if let Some(item) = item { - self.get(item).tasks[row] as usize + fn index(&self, index: Option, row: usize) -> usize { + if let Some(index) = index { + self.get(index).tasks[row] as usize } else { self.p.top[row] as usize } } - fn parent(&self, item: usize) -> Option { - self.get(item).process.parent.map(|pid| pid as usize) + fn parent(&self, index: usize) -> Option { + self.get(index).process.parent.map(|pid| pid as usize) } - fn can_fetch_more(&self, item: Option) -> bool { - if item.is_some() || !self.active { + fn can_fetch_more(&self, index: Option) -> bool { + if index.is_some() || !self.active { return false; } if let Ok(ref incoming) = self.incoming.try_lock() { @@ -364,8 +364,8 @@ impl ProcessesTrait for Processes { false } } - fn fetch_more(&mut self, item: Option) { - if item.is_some() || !self.active { + fn fetch_more(&mut self, index: Option) { + if index.is_some() || !self.active { return; } let new = if let Ok(ref mut incoming) = self.incoming.try_lock() { @@ -387,30 +387,30 @@ impl ProcessesTrait for Processes { } } } - fn row(&self, item: usize) -> usize { - self.get(item).row + fn row(&self, index: usize) -> usize { + self.get(index).row } - fn pid(&self, item: usize) -> u32 { - self.process(item).pid as u32 + fn pid(&self, index: usize) -> u32 { + self.process(index).pid as u32 } - fn uid(&self, item: usize) -> u32 { - self.process(item).uid as u32 + fn uid(&self, index: usize) -> u32 { + self.process(index).uid as u32 } - fn cpu_usage(&self, item: usize) -> f32 { - self.process(item).cpu_usage + fn cpu_usage(&self, index: usize) -> f32 { + self.process(index).cpu_usage } - fn cpu_percentage(&self, item: usize) -> u8 { - let cpu = self.process(item).cpu_usage / self.p.cpusum; + fn cpu_percentage(&self, index: usize) -> u8 { + let cpu = self.process(index).cpu_usage / self.p.cpusum; (cpu * 100.0) as u8 } - fn memory(&self, item: usize) -> u64 { - self.process(item).memory + fn memory(&self, index: usize) -> u64 { + self.process(index).memory } - fn name(&self, item: usize) -> &str { - &self.process(item).name + fn name(&self, index: usize) -> &str { + &self.process(index).name } - fn cmd(&self, item: usize) -> String { - self.process(item).cmd.join(" ") + fn cmd(&self, index: usize) -> String { + self.process(index).cmd.join(" ") } fn active(&self) -> bool { self.active diff --git a/demo/rust/src/interface.rs b/demo/rust/src/interface.rs index e411a3d..7a6a3b3 100644 --- a/demo/rust/src/interface.rs +++ b/demo/rust/src/interface.rs @@ -134,23 +134,23 @@ pub extern "C" fn demo_new( fibonacci_list_end_remove_rows: fn(*const FibonacciListQObject), file_system_tree: *mut FileSystemTreeQObject, path_changed: fn(*const FileSystemTreeQObject), - file_system_tree_new_data_ready: fn(*const FileSystemTreeQObject, item: usize, valid: bool), + file_system_tree_new_data_ready: fn(*const FileSystemTreeQObject, index: usize, valid: bool), file_system_tree_data_changed: fn(*const FileSystemTreeQObject, usize, usize), file_system_tree_begin_reset_model: fn(*const FileSystemTreeQObject), file_system_tree_end_reset_model: fn(*const FileSystemTreeQObject), - file_system_tree_begin_insert_rows: fn(*const FileSystemTreeQObject, item: usize, valid: bool, usize, usize), + file_system_tree_begin_insert_rows: fn(*const FileSystemTreeQObject, index: usize, valid: bool, usize, usize), file_system_tree_end_insert_rows: fn(*const FileSystemTreeQObject), - file_system_tree_begin_remove_rows: fn(*const FileSystemTreeQObject, item: usize, valid: bool, usize, usize), + file_system_tree_begin_remove_rows: fn(*const FileSystemTreeQObject, index: usize, valid: bool, usize, usize), file_system_tree_end_remove_rows: fn(*const FileSystemTreeQObject), processes: *mut ProcessesQObject, active_changed: fn(*const ProcessesQObject), - processes_new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool), + processes_new_data_ready: fn(*const ProcessesQObject, index: usize, valid: bool), processes_data_changed: fn(*const ProcessesQObject, usize, usize), processes_begin_reset_model: fn(*const ProcessesQObject), processes_end_reset_model: fn(*const ProcessesQObject), - processes_begin_insert_rows: fn(*const ProcessesQObject, item: usize, valid: bool, usize, usize), + processes_begin_insert_rows: fn(*const ProcessesQObject, index: usize, valid: bool, usize, usize), processes_end_insert_rows: fn(*const ProcessesQObject), - processes_begin_remove_rows: fn(*const ProcessesQObject, item: usize, valid: bool, usize, usize), + processes_begin_remove_rows: fn(*const ProcessesQObject, index: usize, valid: bool, usize, usize), processes_end_remove_rows: fn(*const ProcessesQObject), time_series: *mut TimeSeriesQObject, time_series_new_data_ready: fn(*const TimeSeriesQObject), @@ -412,8 +412,8 @@ pub trait FibonacciListTrait { } fn fetch_more(&mut self) {} fn sort(&mut self, u8, SortOrder) {} - fn fibonacci_number(&self, item: usize) -> u64; - fn row(&self, item: usize) -> u64; + fn fibonacci_number(&self, index: usize) -> u64; + fn row(&self, index: usize) -> u64; } #[no_mangle] @@ -498,7 +498,7 @@ pub struct FileSystemTreeQObject {} pub struct FileSystemTreeEmitter { qobject: Arc>, path_changed: fn(*const FileSystemTreeQObject), - new_data_ready: fn(*const FileSystemTreeQObject, item: usize, valid: bool), + new_data_ready: fn(*const FileSystemTreeQObject, index: usize, valid: bool), } unsafe impl Send for FileSystemTreeEmitter {} @@ -526,9 +526,9 @@ pub struct FileSystemTreeTree { data_changed: fn(*const FileSystemTreeQObject, usize, usize), begin_reset_model: fn(*const FileSystemTreeQObject), end_reset_model: fn(*const FileSystemTreeQObject), - begin_insert_rows: fn(*const FileSystemTreeQObject, item: usize, valid: bool, usize, usize), + begin_insert_rows: fn(*const FileSystemTreeQObject, index: usize, valid: bool, usize, usize), end_insert_rows: fn(*const FileSystemTreeQObject), - begin_remove_rows: fn(*const FileSystemTreeQObject, item: usize, valid: bool, usize, usize), + begin_remove_rows: fn(*const FileSystemTreeQObject, index: usize, valid: bool, usize, usize), end_remove_rows: fn(*const FileSystemTreeQObject), } @@ -542,14 +542,14 @@ impl FileSystemTreeTree { pub fn end_reset_model(&self) { (self.end_reset_model)(self.qobject); } - pub fn begin_insert_rows(&self, item: Option, first: usize, last: usize) { - (self.begin_insert_rows)(self.qobject, item.unwrap_or(13), item.is_some(), first, last); + pub fn begin_insert_rows(&self, index: Option, first: usize, last: usize) { + (self.begin_insert_rows)(self.qobject, index.unwrap_or(13), index.is_some(), first, last); } pub fn end_insert_rows(&self) { (self.end_insert_rows)(self.qobject); } - pub fn begin_remove_rows(&self, item: Option, first: usize, last: usize) { - (self.begin_remove_rows)(self.qobject, item.unwrap_or(13), item.is_some(), first, last); + pub fn begin_remove_rows(&self, index: Option, first: usize, last: usize) { + (self.begin_remove_rows)(self.qobject, index.unwrap_or(13), index.is_some(), first, last); } pub fn end_remove_rows(&self) { (self.end_remove_rows)(self.qobject); @@ -568,27 +568,27 @@ pub trait FileSystemTreeTrait { fn fetch_more(&mut self, Option) {} fn sort(&mut self, u8, SortOrder) {} fn index(&self, item: Option, row: usize) -> usize; - fn parent(&self, item: usize) -> Option; - fn row(&self, item: usize) -> usize; - fn file_icon(&self, item: usize) -> &[u8]; - fn file_name(&self, item: usize) -> String; - fn file_path(&self, item: usize) -> Option; - fn file_permissions(&self, item: usize) -> i32; - fn file_size(&self, item: usize) -> Option; - fn file_type(&self, item: usize) -> i32; + fn parent(&self, index: usize) -> Option; + fn row(&self, index: usize) -> usize; + fn file_icon(&self, index: usize) -> &[u8]; + fn file_name(&self, index: usize) -> String; + fn file_path(&self, index: usize) -> Option; + fn file_permissions(&self, index: usize) -> i32; + fn file_size(&self, index: usize) -> Option; + fn file_type(&self, index: usize) -> i32; } #[no_mangle] pub extern "C" fn file_system_tree_new( file_system_tree: *mut FileSystemTreeQObject, path_changed: fn(*const FileSystemTreeQObject), - file_system_tree_new_data_ready: fn(*const FileSystemTreeQObject, item: usize, valid: bool), + file_system_tree_new_data_ready: fn(*const FileSystemTreeQObject, index: usize, valid: bool), file_system_tree_data_changed: fn(*const FileSystemTreeQObject, usize, usize), file_system_tree_begin_reset_model: fn(*const FileSystemTreeQObject), file_system_tree_end_reset_model: fn(*const FileSystemTreeQObject), - file_system_tree_begin_insert_rows: fn(*const FileSystemTreeQObject, item: usize, valid: bool, usize, usize), + file_system_tree_begin_insert_rows: fn(*const FileSystemTreeQObject, index: usize, valid: bool, usize, usize), file_system_tree_end_insert_rows: fn(*const FileSystemTreeQObject), - file_system_tree_begin_remove_rows: fn(*const FileSystemTreeQObject, item: usize, valid: bool, usize, usize), + file_system_tree_begin_remove_rows: fn(*const FileSystemTreeQObject, index: usize, valid: bool, usize, usize), file_system_tree_end_remove_rows: fn(*const FileSystemTreeQObject), ) -> *mut FileSystemTree { let file_system_tree_emit = FileSystemTreeEmitter { @@ -646,11 +646,11 @@ pub extern "C" fn file_system_tree_path_set_none(ptr: *mut FileSystemTree) { #[no_mangle] pub unsafe extern "C" fn file_system_tree_row_count( ptr: *const FileSystemTree, - item: usize, + index: usize, valid: bool, ) -> c_int { to_c_int(if valid { - (&*ptr).row_count(Some(item)) + (&*ptr).row_count(Some(index)) } else { (&*ptr).row_count(None) }) @@ -658,19 +658,19 @@ pub unsafe extern "C" fn file_system_tree_row_count( #[no_mangle] pub unsafe extern "C" fn file_system_tree_can_fetch_more( ptr: *const FileSystemTree, - item: usize, + index: usize, valid: bool, ) -> bool { if valid { - (&*ptr).can_fetch_more(Some(item)) + (&*ptr).can_fetch_more(Some(index)) } else { (&*ptr).can_fetch_more(None) } } #[no_mangle] -pub unsafe extern "C" fn file_system_tree_fetch_more(ptr: *mut FileSystemTree, item: usize, valid: bool) { +pub unsafe extern "C" fn file_system_tree_fetch_more(ptr: *mut FileSystemTree, index: usize, valid: bool) { if valid { - (&mut *ptr).fetch_more(Some(item)) + (&mut *ptr).fetch_more(Some(index)) } else { (&mut *ptr).fetch_more(None) } @@ -686,14 +686,14 @@ pub unsafe extern "C" fn file_system_tree_sort( #[no_mangle] pub unsafe extern "C" fn file_system_tree_index( ptr: *const FileSystemTree, - item: usize, + index: usize, valid: bool, row: c_int, ) -> usize { if !valid { (&*ptr).index(None, to_usize(row)) } else { - (&*ptr).index(Some(item), to_usize(row)) + (&*ptr).index(Some(index), to_usize(row)) } } #[no_mangle] @@ -711,42 +711,42 @@ pub unsafe extern "C" fn file_system_tree_parent(ptr: *const FileSystemTree, ind } } #[no_mangle] -pub unsafe extern "C" fn file_system_tree_row(ptr: *const FileSystemTree, item: usize) -> c_int { - to_c_int((&*ptr).row(item)) +pub unsafe extern "C" fn file_system_tree_row(ptr: *const FileSystemTree, index: usize) -> c_int { + to_c_int((&*ptr).row(index)) } #[no_mangle] pub extern "C" fn file_system_tree_data_file_icon( - ptr: *const FileSystemTree, item: usize, + ptr: *const FileSystemTree, index: usize, d: *mut QByteArray, set: fn(*mut QByteArray, *const c_char, len: c_int), ) { let o = unsafe { &*ptr }; - let data = o.file_icon(item); + let data = o.file_icon(index); let s: *const c_char = data.as_ptr() as (*const c_char); set(d, s, to_c_int(data.len())); } #[no_mangle] pub extern "C" fn file_system_tree_data_file_name( - ptr: *const FileSystemTree, item: usize, + ptr: *const FileSystemTree, index: usize, d: *mut QString, set: fn(*mut QString, *const c_char, len: c_int), ) { let o = unsafe { &*ptr }; - let data = o.file_name(item); + let data = o.file_name(index); let s: *const c_char = data.as_ptr() as (*const c_char); set(d, s, to_c_int(data.len())); } #[no_mangle] pub extern "C" fn file_system_tree_data_file_path( - ptr: *const FileSystemTree, item: usize, + ptr: *const FileSystemTree, index: usize, d: *mut QString, set: fn(*mut QString, *const c_char, len: c_int), ) { let o = unsafe { &*ptr }; - let data = o.file_path(item); + let data = o.file_path(index); if let Some(data) = data { let s: *const c_char = data.as_ptr() as (*const c_char); set(d, s, to_c_int(data.len())); @@ -754,21 +754,21 @@ pub extern "C" fn file_system_tree_data_file_path( } #[no_mangle] -pub extern "C" fn file_system_tree_data_file_permissions(ptr: *const FileSystemTree, item: usize) -> i32 { +pub extern "C" fn file_system_tree_data_file_permissions(ptr: *const FileSystemTree, index: usize) -> i32 { let o = unsafe { &*ptr }; - o.file_permissions(item).into() + o.file_permissions(index).into() } #[no_mangle] -pub extern "C" fn file_system_tree_data_file_size(ptr: *const FileSystemTree, item: usize) -> COption { +pub extern "C" fn file_system_tree_data_file_size(ptr: *const FileSystemTree, index: usize) -> COption { let o = unsafe { &*ptr }; - o.file_size(item).into() + o.file_size(index).into() } #[no_mangle] -pub extern "C" fn file_system_tree_data_file_type(ptr: *const FileSystemTree, item: usize) -> i32 { +pub extern "C" fn file_system_tree_data_file_type(ptr: *const FileSystemTree, index: usize) -> i32 { let o = unsafe { &*ptr }; - o.file_type(item).into() + o.file_type(index).into() } pub struct ProcessesQObject {} @@ -777,7 +777,7 @@ pub struct ProcessesQObject {} pub struct ProcessesEmitter { qobject: Arc>, active_changed: fn(*const ProcessesQObject), - new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool), + new_data_ready: fn(*const ProcessesQObject, index: usize, valid: bool), } unsafe impl Send for ProcessesEmitter {} @@ -805,9 +805,9 @@ pub struct ProcessesTree { data_changed: fn(*const ProcessesQObject, usize, usize), begin_reset_model: fn(*const ProcessesQObject), end_reset_model: fn(*const ProcessesQObject), - begin_insert_rows: fn(*const ProcessesQObject, item: usize, valid: bool, usize, usize), + begin_insert_rows: fn(*const ProcessesQObject, index: usize, valid: bool, usize, usize), end_insert_rows: fn(*const ProcessesQObject), - begin_remove_rows: fn(*const ProcessesQObject, item: usize, valid: bool, usize, usize), + begin_remove_rows: fn(*const ProcessesQObject, index: usize, valid: bool, usize, usize), end_remove_rows: fn(*const ProcessesQObject), } @@ -821,14 +821,14 @@ impl ProcessesTree { pub fn end_reset_model(&self) { (self.end_reset_model)(self.qobject); } - pub fn begin_insert_rows(&self, item: Option, first: usize, last: usize) { - (self.begin_insert_rows)(self.qobject, item.unwrap_or(13), item.is_some(), first, last); + pub fn begin_insert_rows(&self, index: Option, first: usize, last: usize) { + (self.begin_insert_rows)(self.qobject, index.unwrap_or(13), index.is_some(), first, last); } pub fn end_insert_rows(&self) { (self.end_insert_rows)(self.qobject); } - pub fn begin_remove_rows(&self, item: Option, first: usize, last: usize) { - (self.begin_remove_rows)(self.qobject, item.unwrap_or(13), item.is_some(), first, last); + pub fn begin_remove_rows(&self, index: Option, first: usize, last: usize) { + (self.begin_remove_rows)(self.qobject, index.unwrap_or(13), index.is_some(), first, last); } pub fn end_remove_rows(&self) { (self.end_remove_rows)(self.qobject); @@ -847,28 +847,28 @@ pub trait ProcessesTrait { fn fetch_more(&mut self, Option) {} fn sort(&mut self, u8, SortOrder) {} fn index(&self, item: Option, row: usize) -> usize; - fn parent(&self, item: usize) -> Option; - fn row(&self, item: usize) -> usize; - fn cmd(&self, item: usize) -> String; - fn cpu_percentage(&self, item: usize) -> u8; - fn cpu_usage(&self, item: usize) -> f32; - fn memory(&self, item: usize) -> u64; - fn name(&self, item: usize) -> &str; - fn pid(&self, item: usize) -> u32; - fn uid(&self, item: usize) -> u32; + fn parent(&self, index: usize) -> Option; + fn row(&self, index: usize) -> usize; + fn cmd(&self, index: usize) -> String; + fn cpu_percentage(&self, index: usize) -> u8; + fn cpu_usage(&self, index: usize) -> f32; + fn memory(&self, index: usize) -> u64; + fn name(&self, index: usize) -> &str; + fn pid(&self, index: usize) -> u32; + fn uid(&self, index: usize) -> u32; } #[no_mangle] pub extern "C" fn processes_new( processes: *mut ProcessesQObject, active_changed: fn(*const ProcessesQObject), - processes_new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool), + processes_new_data_ready: fn(*const ProcessesQObject, index: usize, valid: bool), processes_data_changed: fn(*const ProcessesQObject, usize, usize), processes_begin_reset_model: fn(*const ProcessesQObject), processes_end_reset_model: fn(*const ProcessesQObject), - processes_begin_insert_rows: fn(*const ProcessesQObject, item: usize, valid: bool, usize, usize), + processes_begin_insert_rows: fn(*const ProcessesQObject, index: usize, valid: bool, usize, usize), processes_end_insert_rows: fn(*const ProcessesQObject), - processes_begin_remove_rows: fn(*const ProcessesQObject, item: usize, valid: bool, usize, usize), + processes_begin_remove_rows: fn(*const ProcessesQObject, index: usize, valid: bool, usize, usize), processes_end_remove_rows: fn(*const ProcessesQObject), ) -> *mut Processes { let processes_emit = ProcessesEmitter { @@ -908,11 +908,11 @@ pub unsafe extern "C" fn processes_active_set(ptr: *mut Processes, v: bool) { #[no_mangle] pub unsafe extern "C" fn processes_row_count( ptr: *const Processes, - item: usize, + index: usize, valid: bool, ) -> c_int { to_c_int(if valid { - (&*ptr).row_count(Some(item)) + (&*ptr).row_count(Some(index)) } else { (&*ptr).row_count(None) }) @@ -920,19 +920,19 @@ pub unsafe extern "C" fn processes_row_count( #[no_mangle] pub unsafe extern "C" fn processes_can_fetch_more( ptr: *const Processes, - item: usize, + index: usize, valid: bool, ) -> bool { if valid { - (&*ptr).can_fetch_more(Some(item)) + (&*ptr).can_fetch_more(Some(index)) } else { (&*ptr).can_fetch_more(None) } } #[no_mangle] -pub unsafe extern "C" fn processes_fetch_more(ptr: *mut Processes, item: usize, valid: bool) { +pub unsafe extern "C" fn processes_fetch_more(ptr: *mut Processes, index: usize, valid: bool) { if valid { - (&mut *ptr).fetch_more(Some(item)) + (&mut *ptr).fetch_more(Some(index)) } else { (&mut *ptr).fetch_more(None) } @@ -948,14 +948,14 @@ pub unsafe extern "C" fn processes_sort( #[no_mangle] pub unsafe extern "C" fn processes_index( ptr: *const Processes, - item: usize, + index: usize, valid: bool, row: c_int, ) -> usize { if !valid { (&*ptr).index(None, to_usize(row)) } else { - (&*ptr).index(Some(item), to_usize(row)) + (&*ptr).index(Some(index), to_usize(row)) } } #[no_mangle] @@ -973,62 +973,62 @@ pub unsafe extern "C" fn processes_parent(ptr: *const Processes, index: usize) - } } #[no_mangle] -pub unsafe extern "C" fn processes_row(ptr: *const Processes, item: usize) -> c_int { - to_c_int((&*ptr).row(item)) +pub unsafe extern "C" fn processes_row(ptr: *const Processes, index: usize) -> c_int { + to_c_int((&*ptr).row(index)) } #[no_mangle] pub extern "C" fn processes_data_cmd( - ptr: *const Processes, item: usize, + ptr: *const Processes, index: usize, d: *mut QString, set: fn(*mut QString, *const c_char, len: c_int), ) { let o = unsafe { &*ptr }; - let data = o.cmd(item); + let data = o.cmd(index); let s: *const c_char = data.as_ptr() as (*const c_char); set(d, s, to_c_int(data.len())); } #[no_mangle] -pub extern "C" fn processes_data_cpu_percentage(ptr: *const Processes, item: usize) -> u8 { +pub extern "C" fn processes_data_cpu_percentage(ptr: *const Processes, index: usize) -> u8 { let o = unsafe { &*ptr }; - o.cpu_percentage(item).into() + o.cpu_percentage(index).into() } #[no_mangle] -pub extern "C" fn processes_data_cpu_usage(ptr: *const Processes, item: usize) -> f32 { +pub extern "C" fn processes_data_cpu_usage(ptr: *const Processes, index: usize) -> f32 { let o = unsafe { &*ptr }; - o.cpu_usage(item).into() + o.cpu_usage(index).into() } #[no_mangle] -pub extern "C" fn processes_data_memory(ptr: *const Processes, item: usize) -> u64 { +pub extern "C" fn processes_data_memory(ptr: *const Processes, index: usize) -> u64 { let o = unsafe { &*ptr }; - o.memory(item).into() + o.memory(index).into() } #[no_mangle] pub extern "C" fn processes_data_name( - ptr: *const Processes, item: usize, + ptr: *const Processes, index: usize, d: *mut QString, set: fn(*mut QString, *const c_char, len: c_int), ) { let o = unsafe { &*ptr }; - let data = o.name(item); + let data = o.name(index); let s: *const c_char = data.as_ptr() as (*const c_char); set(d, s, to_c_int(data.len())); } #[no_mangle] -pub extern "C" fn processes_data_pid(ptr: *const Processes, item: usize) -> u32 { +pub extern "C" fn processes_data_pid(ptr: *const Processes, index: usize) -> u32 { let o = unsafe { &*ptr }; - o.pid(item).into() + o.pid(index).into() } #[no_mangle] -pub extern "C" fn processes_data_uid(ptr: *const Processes, item: usize) -> u32 { +pub extern "C" fn processes_data_uid(ptr: *const Processes, index: usize) -> u32 { let o = unsafe { &*ptr }; - o.uid(item).into() + o.uid(index).into() } pub struct TimeSeriesQObject {} @@ -1099,12 +1099,12 @@ pub trait TimeSeriesTrait { } fn fetch_more(&mut self) {} fn sort(&mut self, u8, SortOrder) {} - fn cos(&self, item: usize) -> f32; - fn set_cos(&mut self, item: usize, f32) -> bool; - fn sin(&self, item: usize) -> f32; - fn set_sin(&mut self, item: usize, f32) -> bool; - fn time(&self, item: usize) -> f32; - fn set_time(&mut self, item: usize, f32) -> bool; + fn cos(&self, index: usize) -> f32; + fn set_cos(&mut self, index: usize, f32) -> bool; + fn sin(&self, index: usize) -> f32; + fn set_sin(&mut self, index: usize, f32) -> bool; + fn time(&self, index: usize) -> f32; + fn set_time(&mut self, index: usize, f32) -> bool; } #[no_mangle] diff --git a/examples/todos/rust/src/implementation.rs b/examples/todos/rust/src/implementation.rs index 0b93095..b300ff0 100644 --- a/examples/todos/rust/src/implementation.rs +++ b/examples/todos/rust/src/implementation.rs @@ -44,32 +44,32 @@ impl TodosTrait for Todos { fn row_count(&self) -> usize { self.list.len() } - fn completed(&self, item: usize) -> bool { - if item >= self.list.len() { + fn completed(&self, index: usize) -> bool { + if index >= self.list.len() { return false; } - self.list[item].completed + self.list[index].completed } - fn set_completed(&mut self, item: usize, v: bool) -> bool { - if item >= self.list.len() { + fn set_completed(&mut self, index: usize, v: bool) -> bool { + if index >= self.list.len() { return false; } - self.list[item].completed = v; + self.list[index].completed = v; self.update_active_count(); true } - fn description(&self, item: usize) -> &str { - if item < self.list.len() { - &self.list[item].description + fn description(&self, index: usize) -> &str { + if index < self.list.len() { + &self.list[index].description } else { "" } } - fn set_description(&mut self, item: usize, v: String) -> bool { - if item >= self.list.len() { + fn set_description(&mut self, index: usize, v: String) -> bool { + if index >= self.list.len() { return false; } - self.list[item].description = v; + self.list[index].description = v; true } fn insert_rows(&mut self, row: usize, count: usize) -> bool { diff --git a/examples/todos/rust/src/interface.rs b/examples/todos/rust/src/interface.rs index a5135ad..8de0c1a 100644 --- a/examples/todos/rust/src/interface.rs +++ b/examples/todos/rust/src/interface.rs @@ -167,10 +167,10 @@ pub trait TodosTrait { } fn fetch_more(&mut self) {} fn sort(&mut self, u8, SortOrder) {} - fn completed(&self, item: usize) -> bool; - fn set_completed(&mut self, item: usize, bool) -> bool; - fn description(&self, item: usize) -> &str; - fn set_description(&mut self, item: usize, String) -> bool; + fn completed(&self, index: usize) -> bool; + fn set_completed(&mut self, index: usize, bool) -> bool; + fn description(&self, index: usize) -> &str; + fn set_description(&mut self, index: usize, String) -> bool; } #[no_mangle] diff --git a/src/rust.cpp b/src/rust.cpp index 1d47e6e..e9c7e5d 100644 --- a/src/rust.cpp +++ b/src/rust.cpp @@ -82,13 +82,13 @@ void rConstructorArgsDecl(QTextStream& r, const QString& name, const Object& o, r << QString(",\n %2_new_data_ready: fn(*const %1QObject)") .arg(o.name, snakeCase(o.name)); } else if (o.type == ObjectType::Tree) { - r << QString(",\n %2_new_data_ready: fn(*const %1QObject, item: usize, valid: bool)") + r << QString(",\n %2_new_data_ready: fn(*const %1QObject, index: usize, valid: bool)") .arg(o.name, snakeCase(o.name)); } if (o.type != ObjectType::Object) { QString indexDecl; if (o.type == ObjectType::Tree) { - indexDecl = " item: usize, valid: bool,"; + indexDecl = " index: usize, valid: bool,"; } r << QString(R"(, %3_data_changed: fn(*const %1QObject, usize, usize), @@ -221,7 +221,7 @@ pub struct %1Emitter { r << QString(" new_data_ready: fn(*const %1QObject),\n") .arg(o.name); } else if (o.type == ObjectType::Tree) { - r << QString(" new_data_ready: fn(*const %1QObject, item: usize, valid: bool),\n") + r << QString(" new_data_ready: fn(*const %1QObject, index: usize, valid: bool),\n") .arg(o.name); } r << QString(R"(} @@ -271,9 +271,9 @@ impl %1Emitter { QString indexDecl; QString indexCDecl; if (o.type == ObjectType::Tree) { - indexDecl = " item: Option,"; - indexCDecl = " item: usize, valid: bool,"; - index = " item.unwrap_or(13), item.is_some(),"; + indexDecl = " index: Option,"; + indexCDecl = " index: usize, valid: bool,"; + index = " index.unwrap_or(13), index.is_some(),"; } r << QString(R"(} @@ -375,25 +375,25 @@ pub trait %1Trait { fn fetch_more(&mut self, Option) {} fn sort(&mut self, u8, SortOrder) {} fn index(&self, item: Option, row: usize) -> usize; - fn parent(&self, item: usize) -> Option; - fn row(&self, item: usize) -> usize; + fn parent(&self, index: usize) -> Option; + fn row(&self, index: usize) -> usize; )"; } if (o.type != ObjectType::Object) { for (auto ip: o.itemProperties) { - r << QString(" fn %1(&self, item: usize) -> %2;\n") + r << QString(" fn %1(&self, index: usize) -> %2;\n") .arg(snakeCase(ip.name), rustReturnType(ip)); if (ip.write) { if (ip.type.name == "QByteArray") { if (ip.optional) { - r << QString(" fn set_%1(&mut self, item: usize, Option<&[u8]>) -> bool;\n") + r << QString(" fn set_%1(&mut self, index: usize, Option<&[u8]>) -> bool;\n") .arg(snakeCase(ip.name)); } else { - r << QString(" fn set_%1(&mut self, item: usize, &[u8]) -> bool;\n") + r << QString(" fn set_%1(&mut self, index: usize, &[u8]) -> bool;\n") .arg(snakeCase(ip.name)); } } else { - r << QString(" fn set_%1(&mut self, item: usize, %2) -> bool;\n") + r << QString(" fn set_%1(&mut self, index: usize, %2) -> bool;\n") .arg(snakeCase(ip.name), rustType(ip)); } } @@ -580,11 +580,11 @@ pub unsafe extern "C" fn %2_sort( #[no_mangle] pub unsafe extern "C" fn %2_row_count( ptr: *const %1, - item: usize, + index: usize, valid: bool, ) -> c_int { to_c_int(if valid { - (&*ptr).row_count(Some(item)) + (&*ptr).row_count(Some(index)) } else { (&*ptr).row_count(None) }) @@ -592,19 +592,19 @@ pub unsafe extern "C" fn %2_row_count( #[no_mangle] pub unsafe extern "C" fn %2_can_fetch_more( ptr: *const %1, - item: usize, + index: usize, valid: bool, ) -> bool { if valid { - (&*ptr).can_fetch_more(Some(item)) + (&*ptr).can_fetch_more(Some(index)) } else { (&*ptr).can_fetch_more(None) } } #[no_mangle] -pub unsafe extern "C" fn %2_fetch_more(ptr: *mut %1, item: usize, valid: bool) { +pub unsafe extern "C" fn %2_fetch_more(ptr: *mut %1, index: usize, valid: bool) { if valid { - (&mut *ptr).fetch_more(Some(item)) + (&mut *ptr).fetch_more(Some(index)) } else { (&mut *ptr).fetch_more(None) } @@ -620,14 +620,14 @@ pub unsafe extern "C" fn %2_sort( #[no_mangle] pub unsafe extern "C" fn %2_index( ptr: *const %1, - item: usize, + index: usize, valid: bool, row: c_int, ) -> usize { if !valid { (&*ptr).index(None, to_usize(row)) } else { - (&*ptr).index(Some(item), to_usize(row)) + (&*ptr).index(Some(index), to_usize(row)) } } #[no_mangle] @@ -645,8 +645,8 @@ pub unsafe extern "C" fn %2_parent(ptr: *const %1, index: usize) -> QModelIndex } } #[no_mangle] -pub unsafe extern "C" fn %2_row(ptr: *const %1, item: usize) -> c_int { - to_c_int((&*ptr).row(item)) +pub unsafe extern "C" fn %2_row(ptr: *const %1, index: usize) -> c_int { + to_c_int((&*ptr).row(index)) } )").arg(o.name, lcname); } @@ -654,8 +654,8 @@ pub unsafe extern "C" fn %2_row(ptr: *const %1, item: usize) -> c_int { QString indexDecl = ", row: c_int"; QString index = "to_usize(row)"; if (o.type == ObjectType::Tree) { - indexDecl = ", item: usize"; - index = "item"; + indexDecl = ", index: usize"; + index = "index"; } for (auto ip: o.itemProperties) { if (ip.type.isComplex() && !ip.optional) { @@ -1002,10 +1002,10 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) { fn index(&self, item: Option, row: usize) -> usize { 0 } - fn parent(&self, item: usize) -> Option { + fn parent(&self, index: usize) -> Option { None } - fn row(&self, item: usize) -> usize { + fn row(&self, index: usize) -> usize { item } )"; @@ -1013,11 +1013,11 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) { if (o.type != ObjectType::Object) { QString index; if (o.type == ObjectType::Tree) { - index = ", item: usize"; + index = ", index: usize"; } for (auto ip: o.itemProperties) { const QString lc(snakeCase(ip.name)); - r << QString(" fn %1(&self, item: usize) -> %2 {\n") + r << QString(" fn %1(&self, index: usize) -> %2 {\n") .arg(lc, rustReturnType(ip)); if (ip.type.isComplex()) { r << " &self.list[item]." << lc << "\n"; @@ -1026,7 +1026,7 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) { } r << " }\n"; if (ip.write) { - r << QString(" fn set_%1(&mut self, item: usize, v: %2) -> bool {\n") + r << QString(" fn set_%1(&mut self, index: usize, v: %2) -> bool {\n") .arg(snakeCase(ip.name), rustType(ip)); r << " self.list[item]." << lc << " = v;\n"; r << " true\n"; diff --git a/tests/rust_list/src/implementation.rs b/tests/rust_list/src/implementation.rs index 6149563..d71a2c2 100644 --- a/tests/rust_list/src/implementation.rs +++ b/tests/rust_list/src/implementation.rs @@ -29,11 +29,11 @@ impl PersonsTrait for Persons { fn row_count(&self) -> usize { self.list.len() } - fn user_name(&self, item: usize) -> &str { - &self.list[item].user_name + fn user_name(&self, index: usize) -> &str { + &self.list[index].user_name } - fn set_user_name(&mut self, item: usize, v: String) -> bool { - self.list[item].user_name = v; + fn set_user_name(&mut self, index: usize, v: String) -> bool { + self.list[index].user_name = v; true } } @@ -58,18 +58,18 @@ impl NoRoleTrait for NoRole { fn row_count(&self) -> usize { self.list.len() } - fn user_name(&self, item: usize) -> &str { - &self.list[item].user_name + fn user_name(&self, index: usize) -> &str { + &self.list[index].user_name } - fn set_user_name(&mut self, item: usize, v: String) -> bool { - self.list[item].user_name = v; + fn set_user_name(&mut self, index: usize, v: String) -> bool { + self.list[index].user_name = v; true } - fn user_age(&self, item: usize) -> u8 { - self.list[item].age + fn user_age(&self, index: usize) -> u8 { + self.list[index].age } - fn set_user_age(&mut self, item: usize, v: u8) -> bool { - self.list[item].age = v; + fn set_user_age(&mut self, index: usize, v: u8) -> bool { + self.list[index].age = v; true } } diff --git a/tests/rust_list/src/interface.rs b/tests/rust_list/src/interface.rs index 972e14e..2ffc972 100644 --- a/tests/rust_list/src/interface.rs +++ b/tests/rust_list/src/interface.rs @@ -147,10 +147,10 @@ pub trait NoRoleTrait { } fn fetch_more(&mut self) {} fn sort(&mut self, u8, SortOrder) {} - fn user_age(&self, item: usize) -> u8; - fn set_user_age(&mut self, item: usize, u8) -> bool; - fn user_name(&self, item: usize) -> &str; - fn set_user_name(&mut self, item: usize, String) -> bool; + fn user_age(&self, index: usize) -> u8; + fn set_user_age(&mut self, index: usize, u8) -> bool; + fn user_name(&self, index: usize) -> &str; + fn set_user_name(&mut self, index: usize, String) -> bool; } #[no_mangle] @@ -322,8 +322,8 @@ pub trait PersonsTrait { } fn fetch_more(&mut self) {} fn sort(&mut self, u8, SortOrder) {} - fn user_name(&self, item: usize) -> &str; - fn set_user_name(&mut self, item: usize, String) -> bool; + fn user_name(&self, index: usize) -> &str; + fn set_user_name(&mut self, index: usize, String) -> bool; } #[no_mangle] diff --git a/tests/rust_list_types/src/implementation.rs b/tests/rust_list_types/src/implementation.rs index 770e85d..f9a62ef 100644 --- a/tests/rust_list_types/src/implementation.rs +++ b/tests/rust_list_types/src/implementation.rs @@ -43,117 +43,117 @@ impl ListTrait for List { fn row_count(&self) -> usize { self.list.len() } - fn boolean(&self, item: usize) -> bool { - self.list[item].boolean + fn boolean(&self, index: usize) -> bool { + self.list[index].boolean } - fn set_boolean(&mut self, item: usize, v: bool) -> bool { - self.list[item].boolean = v; + fn set_boolean(&mut self, index: usize, v: bool) -> bool { + self.list[index].boolean = v; true } - fn optional_boolean(&self, item: usize) -> Option { - self.list[item].optional_boolean + fn optional_boolean(&self, index: usize) -> Option { + self.list[index].optional_boolean } - fn set_optional_boolean(&mut self, item: usize, v: Option) -> bool { - self.list[item].optional_boolean = v; + fn set_optional_boolean(&mut self, index: usize, v: Option) -> bool { + self.list[index].optional_boolean = v; true } - fn i8(&self, item: usize) -> i8 { - self.list[item].i8 + fn i8(&self, index: usize) -> i8 { + self.list[index].i8 } - fn set_i8(&mut self, item: usize, v: i8) -> bool { - self.list[item].i8 = v; + fn set_i8(&mut self, index: usize, v: i8) -> bool { + self.list[index].i8 = v; true } - fn u8(&self, item: usize) -> u8 { - self.list[item].u8 + fn u8(&self, index: usize) -> u8 { + self.list[index].u8 } - fn set_u8(&mut self, item: usize, v: u8) -> bool { - self.list[item].u8 = v; + fn set_u8(&mut self, index: usize, v: u8) -> bool { + self.list[index].u8 = v; true } - fn i16(&self, item: usize) -> i16 { - self.list[item].i16 + fn i16(&self, index: usize) -> i16 { + self.list[index].i16 } - fn set_i16(&mut self, item: usize, v: i16) -> bool { - self.list[item].i16 = v; + fn set_i16(&mut self, index: usize, v: i16) -> bool { + self.list[index].i16 = v; true } - fn u16(&self, item: usize) -> u16 { - self.list[item].u16 + fn u16(&self, index: usize) -> u16 { + self.list[index].u16 } - fn set_u16(&mut self, item: usize, v: u16) -> bool { - self.list[item].u16 = v; + fn set_u16(&mut self, index: usize, v: u16) -> bool { + self.list[index].u16 = v; true } - fn i32(&self, item: usize) -> i32 { - self.list[item].i32 + fn i32(&self, index: usize) -> i32 { + self.list[index].i32 } - fn set_i32(&mut self, item: usize, v: i32) -> bool { - self.list[item].i32 = v; + fn set_i32(&mut self, index: usize, v: i32) -> bool { + self.list[index].i32 = v; true } - fn u32(&self, item: usize) -> u32 { - self.list[item].u32 + fn u32(&self, index: usize) -> u32 { + self.list[index].u32 } - fn set_u32(&mut self, item: usize, v: u32) -> bool { - self.list[item].u32 = v; + fn set_u32(&mut self, index: usize, v: u32) -> bool { + self.list[index].u32 = v; true } - fn i64(&self, item: usize) -> i64 { - self.list[item].i64 + fn i64(&self, index: usize) -> i64 { + self.list[index].i64 } - fn set_i64(&mut self, item: usize, v: i64) -> bool { - self.list[item].i64 = v; + fn set_i64(&mut self, index: usize, v: i64) -> bool { + self.list[index].i64 = v; true } - fn u64(&self, item: usize) -> u64 { - self.list[item].u64 + fn u64(&self, index: usize) -> u64 { + self.list[index].u64 } - fn set_u64(&mut self, item: usize, v: u64) -> bool { - self.list[item].u64 = v; + fn set_u64(&mut self, index: usize, v: u64) -> bool { + self.list[index].u64 = v; true } - fn f32(&self, item: usize) -> f32 { - self.list[item].f32 + fn f32(&self, index: usize) -> f32 { + self.list[index].f32 } - fn set_f32(&mut self, item: usize, v: f32) -> bool { - self.list[item].f32 = v; + fn set_f32(&mut self, index: usize, v: f32) -> bool { + self.list[index].f32 = v; true } - fn f64(&self, item: usize) -> f64 { - self.list[item].f64 + fn f64(&self, index: usize) -> f64 { + self.list[index].f64 } - fn set_f64(&mut self, item: usize, v: f64) -> bool { - self.list[item].f64 = v; + fn set_f64(&mut self, index: usize, v: f64) -> bool { + self.list[index].f64 = v; true } - fn string(&self, item: usize) -> &str { - &self.list[item].string + fn string(&self, index: usize) -> &str { + &self.list[index].string } - fn set_string(&mut self, item: usize, v: String) -> bool { - self.list[item].string = v; + fn set_string(&mut self, index: usize, v: String) -> bool { + self.list[index].string = v; true } - fn optional_string(&self, item: usize) -> Option<&str> { - self.list[item].optional_string.as_ref().map(|p|&p[..]) + fn optional_string(&self, index: usize) -> Option<&str> { + self.list[index].optional_string.as_ref().map(|p|&p[..]) } - fn set_optional_string(&mut self, item: usize, v: Option) -> bool { - self.list[item].optional_string = v; + fn set_optional_string(&mut self, index: usize, v: Option) -> bool { + self.list[index].optional_string = v; true } - fn bytearray(&self, item: usize) -> &[u8] { - &self.list[item].bytearray + fn bytearray(&self, index: usize) -> &[u8] { + &self.list[index].bytearray } - fn set_bytearray(&mut self, item: usize, v: &[u8]) -> bool { - self.list[item].bytearray.truncate(0); - self.list[item].bytearray.extend_from_slice(v); + fn set_bytearray(&mut self, index: usize, v: &[u8]) -> bool { + self.list[index].bytearray.truncate(0); + self.list[index].bytearray.extend_from_slice(v); true } - fn optional_bytearray(&self, item: usize) -> Option<&[u8]> { - self.list[item].optional_bytearray.as_ref().map(|p|&p[..]) + fn optional_bytearray(&self, index: usize) -> Option<&[u8]> { + self.list[index].optional_bytearray.as_ref().map(|p|&p[..]) } - fn set_optional_bytearray(&mut self, item: usize, v: Option<&[u8]>) -> bool { - match (v, &mut self.list[item].optional_bytearray) { + fn set_optional_bytearray(&mut self, index: usize, v: Option<&[u8]>) -> bool { + match (v, &mut self.list[index].optional_bytearray) { (Some(value), &mut Some(ref mut b)) => { b.truncate(0); b.extend_from_slice(value); diff --git a/tests/rust_list_types/src/interface.rs b/tests/rust_list_types/src/interface.rs index be4f34b..bcc76fa 100644 --- a/tests/rust_list_types/src/interface.rs +++ b/tests/rust_list_types/src/interface.rs @@ -150,38 +150,38 @@ pub trait ListTrait { } fn fetch_more(&mut self) {} fn sort(&mut self, u8, SortOrder) {} - fn boolean(&self, item: usize) -> bool; - fn set_boolean(&mut self, item: usize, bool) -> bool; - fn bytearray(&self, item: usize) -> &[u8]; - fn set_bytearray(&mut self, item: usize, &[u8]) -> bool; - fn f32(&self, item: usize) -> f32; - fn set_f32(&mut self, item: usize, f32) -> bool; - fn f64(&self, item: usize) -> f64; - fn set_f64(&mut self, item: usize, f64) -> bool; - fn i16(&self, item: usize) -> i16; - fn set_i16(&mut self, item: usize, i16) -> bool; - fn i32(&self, item: usize) -> i32; - fn set_i32(&mut self, item: usize, i32) -> bool; - fn i64(&self, item: usize) -> i64; - fn set_i64(&mut self, item: usize, i64) -> bool; - fn i8(&self, item: usize) -> i8; - fn set_i8(&mut self, item: usize, i8) -> bool; - fn optional_boolean(&self, item: usize) -> Option; - fn set_optional_boolean(&mut self, item: usize, Option) -> bool; - fn optional_bytearray(&self, item: usize) -> Option<&[u8]>; - fn set_optional_bytearray(&mut self, item: usize, Option<&[u8]>) -> bool; - fn optional_string(&self, item: usize) -> Option<&str>; - fn set_optional_string(&mut self, item: usize, Option) -> bool; - fn string(&self, item: usize) -> &str; - fn set_string(&mut self, item: usize, String) -> bool; - fn u16(&self, item: usize) -> u16; - fn set_u16(&mut self, item: usize, u16) -> bool; - fn u32(&self, item: usize) -> u32; - fn set_u32(&mut self, item: usize, u32) -> bool; - fn u64(&self, item: usize) -> u64; - fn set_u64(&mut self, item: usize, u64) -> bool; - fn u8(&self, item: usize) -> u8; - fn set_u8(&mut self, item: usize, u8) -> bool; + fn boolean(&self, index: usize) -> bool; + fn set_boolean(&mut self, index: usize, bool) -> bool; + fn bytearray(&self, index: usize) -> &[u8]; + fn set_bytearray(&mut self, index: usize, &[u8]) -> bool; + fn f32(&self, index: usize) -> f32; + fn set_f32(&mut self, index: usize, f32) -> bool; + fn f64(&self, index: usize) -> f64; + fn set_f64(&mut self, index: usize, f64) -> bool; + fn i16(&self, index: usize) -> i16; + fn set_i16(&mut self, index: usize, i16) -> bool; + fn i32(&self, index: usize) -> i32; + fn set_i32(&mut self, index: usize, i32) -> bool; + fn i64(&self, index: usize) -> i64; + fn set_i64(&mut self, index: usize, i64) -> bool; + fn i8(&self, index: usize) -> i8; + fn set_i8(&mut self, index: usize, i8) -> bool; + fn optional_boolean(&self, index: usize) -> Option; + fn set_optional_boolean(&mut self, index: usize, Option) -> bool; + fn optional_bytearray(&self, index: usize) -> Option<&[u8]>; + fn set_optional_bytearray(&mut self, index: usize, Option<&[u8]>) -> bool; + fn optional_string(&self, index: usize) -> Option<&str>; + fn set_optional_string(&mut self, index: usize, Option) -> bool; + fn string(&self, index: usize) -> &str; + fn set_string(&mut self, index: usize, String) -> bool; + fn u16(&self, index: usize) -> u16; + fn set_u16(&mut self, index: usize, u16) -> bool; + fn u32(&self, index: usize) -> u32; + fn set_u32(&mut self, index: usize, u32) -> bool; + fn u64(&self, index: usize) -> u64; + fn set_u64(&mut self, index: usize, u64) -> bool; + fn u8(&self, index: usize) -> u8; + fn set_u8(&mut self, index: usize, u8) -> bool; } #[no_mangle] diff --git a/tests/rust_tree/src/implementation.rs b/tests/rust_tree/src/implementation.rs index 1ca5526..47c1c9b 100644 --- a/tests/rust_tree/src/implementation.rs +++ b/tests/rust_tree/src/implementation.rs @@ -25,23 +25,23 @@ impl PersonsTrait for Persons { fn emit(&self) -> &PersonsEmitter { &self.emit } - fn row_count(&self, item: Option) -> usize { + fn row_count(&self, index: Option) -> usize { self.list.len() } - fn index(&self, item: Option, row: usize) -> usize { + fn index(&self, index: Option, row: usize) -> usize { 0 } - fn parent(&self, item: usize) -> Option { + fn parent(&self, index: usize) -> Option { None } - fn row(&self, item: usize) -> usize { - item + fn row(&self, index: usize) -> usize { + index } - fn user_name(&self, item: usize) -> &str { - &self.list[item].user_name + fn user_name(&self, index: usize) -> &str { + &self.list[index].user_name } - fn set_user_name(&mut self, item: usize, v: String) -> bool { - self.list[item].user_name = v; + fn set_user_name(&mut self, index: usize, v: String) -> bool { + self.list[index].user_name = v; true } } diff --git a/tests/rust_tree/src/interface.rs b/tests/rust_tree/src/interface.rs index afa7b8e..1d15dab 100644 --- a/tests/rust_tree/src/interface.rs +++ b/tests/rust_tree/src/interface.rs @@ -84,7 +84,7 @@ pub struct PersonsQObject {} #[derive(Clone)] pub struct PersonsEmitter { qobject: Arc>, - new_data_ready: fn(*const PersonsQObject, item: usize, valid: bool), + new_data_ready: fn(*const PersonsQObject, index: usize, valid: bool), } unsafe impl Send for PersonsEmitter {} @@ -106,9 +106,9 @@ pub struct PersonsTree { data_changed: fn(*const PersonsQObject, usize, usize), begin_reset_model: fn(*const PersonsQObject), end_reset_model: fn(*const PersonsQObject), - begin_insert_rows: fn(*const PersonsQObject, item: usize, valid: bool, usize, usize), + begin_insert_rows: fn(*const PersonsQObject, index: usize, valid: bool, usize, usize), end_insert_rows: fn(*const PersonsQObject), - begin_remove_rows: fn(*const PersonsQObject, item: usize, valid: bool, usize, usize), + begin_remove_rows: fn(*const PersonsQObject, index: usize, valid: bool, usize, usize), end_remove_rows: fn(*const PersonsQObject), } @@ -122,14 +122,14 @@ impl PersonsTree { pub fn end_reset_model(&self) { (self.end_reset_model)(self.qobject); } - pub fn begin_insert_rows(&self, item: Option, first: usize, last: usize) { - (self.begin_insert_rows)(self.qobject, item.unwrap_or(13), item.is_some(), first, last); + pub fn begin_insert_rows(&self, index: Option, first: usize, last: usize) { + (self.begin_insert_rows)(self.qobject, index.unwrap_or(13), index.is_some(), first, last); } pub fn end_insert_rows(&self) { (self.end_insert_rows)(self.qobject); } - pub fn begin_remove_rows(&self, item: Option, first: usize, last: usize) { - (self.begin_remove_rows)(self.qobject, item.unwrap_or(13), item.is_some(), first, last); + pub fn begin_remove_rows(&self, index: Option, first: usize, last: usize) { + (self.begin_remove_rows)(self.qobject, index.unwrap_or(13), index.is_some(), first, last); } pub fn end_remove_rows(&self) { (self.end_remove_rows)(self.qobject); @@ -146,22 +146,22 @@ pub trait PersonsTrait { fn fetch_more(&mut self, Option) {} fn sort(&mut self, u8, SortOrder) {} fn index(&self, item: Option, row: usize) -> usize; - fn parent(&self, item: usize) -> Option; - fn row(&self, item: usize) -> usize; - fn user_name(&self, item: usize) -> &str; - fn set_user_name(&mut self, item: usize, String) -> bool; + fn parent(&self, index: usize) -> Option; + fn row(&self, index: usize) -> usize; + fn user_name(&self, index: usize) -> &str; + fn set_user_name(&mut self, index: usize, String) -> bool; } #[no_mangle] pub extern "C" fn persons_new( persons: *mut PersonsQObject, - persons_new_data_ready: fn(*const PersonsQObject, item: usize, valid: bool), + persons_new_data_ready: fn(*const PersonsQObject, index: usize, valid: bool), persons_data_changed: fn(*const PersonsQObject, usize, usize), persons_begin_reset_model: fn(*const PersonsQObject), persons_end_reset_model: fn(*const PersonsQObject), - persons_begin_insert_rows: fn(*const PersonsQObject, item: usize, valid: bool, usize, usize), + persons_begin_insert_rows: fn(*const PersonsQObject, index: usize, valid: bool, usize, usize), persons_end_insert_rows: fn(*const PersonsQObject), - persons_begin_remove_rows: fn(*const PersonsQObject, item: usize, valid: bool, usize, usize), + persons_begin_remove_rows: fn(*const PersonsQObject, index: usize, valid: bool, usize, usize), persons_end_remove_rows: fn(*const PersonsQObject), ) -> *mut Persons { let persons_emit = PersonsEmitter { @@ -190,11 +190,11 @@ pub unsafe extern "C" fn persons_free(ptr: *mut Persons) { #[no_mangle] pub unsafe extern "C" fn persons_row_count( ptr: *const Persons, - item: usize, + index: usize, valid: bool, ) -> c_int { to_c_int(if valid { - (&*ptr).row_count(Some(item)) + (&*ptr).row_count(Some(index)) } else { (&*ptr).row_count(None) }) @@ -202,19 +202,19 @@ pub unsafe extern "C" fn persons_row_count( #[no_mangle] pub unsafe extern "C" fn persons_can_fetch_more( ptr: *const Persons, - item: usize, + index: usize, valid: bool, ) -> bool { if valid { - (&*ptr).can_fetch_more(Some(item)) + (&*ptr).can_fetch_more(Some(index)) } else { (&*ptr).can_fetch_more(None) } } #[no_mangle] -pub unsafe extern "C" fn persons_fetch_more(ptr: *mut Persons, item: usize, valid: bool) { +pub unsafe extern "C" fn persons_fetch_more(ptr: *mut Persons, index: usize, valid: bool) { if valid { - (&mut *ptr).fetch_more(Some(item)) + (&mut *ptr).fetch_more(Some(index)) } else { (&mut *ptr).fetch_more(None) } @@ -230,14 +230,14 @@ pub unsafe extern "C" fn persons_sort( #[no_mangle] pub unsafe extern "C" fn persons_index( ptr: *const Persons, - item: usize, + index: usize, valid: bool, row: c_int, ) -> usize { if !valid { (&*ptr).index(None, to_usize(row)) } else { - (&*ptr).index(Some(item), to_usize(row)) + (&*ptr).index(Some(index), to_usize(row)) } } #[no_mangle] @@ -255,29 +255,29 @@ pub unsafe extern "C" fn persons_parent(ptr: *const Persons, index: usize) -> QM } } #[no_mangle] -pub unsafe extern "C" fn persons_row(ptr: *const Persons, item: usize) -> c_int { - to_c_int((&*ptr).row(item)) +pub unsafe extern "C" fn persons_row(ptr: *const Persons, index: usize) -> c_int { + to_c_int((&*ptr).row(index)) } #[no_mangle] pub extern "C" fn persons_data_user_name( - ptr: *const Persons, item: usize, + ptr: *const Persons, index: usize, d: *mut QString, set: fn(*mut QString, *const c_char, len: c_int), ) { let o = unsafe { &*ptr }; - let data = o.user_name(item); + let data = o.user_name(index); let s: *const c_char = data.as_ptr() as (*const c_char); set(d, s, to_c_int(data.len())); } #[no_mangle] pub extern "C" fn persons_set_data_user_name( - ptr: *mut Persons, item: usize, + ptr: *mut Persons, index: usize, s: *const c_ushort, len: c_int, ) -> bool { let o = unsafe { &mut *ptr }; let mut v = String::new(); set_string_from_utf16(&mut v, s, len); - o.set_user_name(item, v) + o.set_user_name(index, v) }