mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-25 02:21:37 +08:00
Make WindowAggregate::value pass mutable value ref
This commit is contained in:
parent
476a02a595
commit
3b70307a94
@ -301,7 +301,7 @@ where
|
|||||||
{
|
{
|
||||||
/// Returns the current value of the aggregate. Unlike xFinal, the
|
/// Returns the current value of the aggregate. Unlike xFinal, the
|
||||||
/// implementation should not delete any context.
|
/// implementation should not delete any context.
|
||||||
fn value(&self, acc: Option<&A>) -> Result<T>;
|
fn value(&self, acc: Option<&mut A>) -> Result<T>;
|
||||||
|
|
||||||
/// Removes a row from the current window.
|
/// Removes a row from the current window.
|
||||||
fn inverse(&self, ctx: &mut Context<'_>, acc: &mut A) -> Result<()>;
|
fn inverse(&self, ctx: &mut Context<'_>, acc: &mut A) -> Result<()>;
|
||||||
@ -755,19 +755,10 @@ where
|
|||||||
{
|
{
|
||||||
// Within the xValue callback, it is customary to set N=0 in calls to
|
// Within the xValue callback, it is customary to set N=0 in calls to
|
||||||
// sqlite3_aggregate_context(C,N) so that no pointless memory allocations occur.
|
// sqlite3_aggregate_context(C,N) so that no pointless memory allocations occur.
|
||||||
let a: Option<&A> = match aggregate_context(ctx, 0) {
|
let pac = aggregate_context(ctx, 0).filter(|&pac| {
|
||||||
Some(pac) =>
|
|
||||||
{
|
|
||||||
#[allow(clippy::unnecessary_cast)]
|
#[allow(clippy::unnecessary_cast)]
|
||||||
if (*pac as *mut A).is_null() {
|
!(*pac as *mut A).is_null()
|
||||||
None
|
});
|
||||||
} else {
|
|
||||||
let a = &**pac;
|
|
||||||
Some(a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let r = catch_unwind(|| {
|
let r = catch_unwind(|| {
|
||||||
let boxed_aggr: *mut W = ffi::sqlite3_user_data(ctx).cast::<W>();
|
let boxed_aggr: *mut W = ffi::sqlite3_user_data(ctx).cast::<W>();
|
||||||
@ -775,7 +766,7 @@ where
|
|||||||
!boxed_aggr.is_null(),
|
!boxed_aggr.is_null(),
|
||||||
"Internal error - null aggregate pointer"
|
"Internal error - null aggregate pointer"
|
||||||
);
|
);
|
||||||
(*boxed_aggr).value(a)
|
(*boxed_aggr).value(pac.map(|pac| &mut **pac))
|
||||||
});
|
});
|
||||||
let t = match r {
|
let t = match r {
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
@ -1030,7 +1021,7 @@ mod test {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn value(&self, sum: Option<&i64>) -> Result<Option<i64>> {
|
fn value(&self, sum: Option<&mut i64>) -> Result<Option<i64>> {
|
||||||
Ok(sum.copied())
|
Ok(sum.copied())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user