Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 8ad05c8

Browse files
author
Stephen Clayton
committed
add size to tuple result to allow looping over the contents
1 parent e4baf78 commit 8ad05c8

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

ffi/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,14 @@ pub unsafe extern "C" fn typed_value_value_type_kw(typed_value: *mut Binding) ->
16661666
string_to_c_char(value.clone())
16671667
}
16681668

1669+
/// Returns the size of a `row` as usize
1670+
#[no_mangle]
1671+
pub unsafe extern "C" fn typed_value_list_size(values: *mut Vec<Binding>) -> c_int {
1672+
assert_not_null!(values);
1673+
let values = &*values;
1674+
values.len () as c_int
1675+
}
1676+
16691677
/// Returns the value at the provided `index` as a `Vec<ValueType>`.
16701678
/// If there is no value present at the `index`, a null pointer is returned.
16711679
///

sdks/android/Mentat/library/src/main/java/org/mozilla/mentat/JNA.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class EntityBuilder extends PointerType {}
158158
int typed_value_value_type(TypedValue value);
159159
Pointer typed_value_value_type_kw(TypedValue value);
160160

161+
int typed_value_list_size(TypedValueList rows);
161162
TypedValueList row_at_index(RelResult rows, int index);
162163
RelResultIter typed_value_result_set_into_iter(RelResult rows);
163164
TypedValueList typed_value_result_set_iter_next(RelResultIter iter);

sdks/android/Mentat/library/src/main/java/org/mozilla/mentat/TupleResult.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@
3737
*/
3838
public class TupleResult extends RustObject<JNA.TypedValueList> {
3939

40+
private int size;
41+
4042
public TupleResult(JNA.TypedValueList pointer) {
4143
super(pointer);
44+
this.size = JNA.INSTANCE.typed_value_list_size(super.validPointer());
4245
}
4346

4447
/**
@@ -145,6 +148,14 @@ public UUID asUUID(Integer index) {
145148
JNA.INSTANCE.value_at_index_into_uuid(this.validPointer(), index));
146149
}
147150

151+
/**
152+
* Return the size of the tuple.
153+
* @return The number of items in this tuple
154+
*/
155+
public int size () {
156+
return this.size;
157+
}
158+
148159
@Override
149160
protected void destroyPointer(JNA.TypedValueList p) {
150161
JNA.INSTANCE.typed_value_list_destroy(p);

0 commit comments

Comments
 (0)