Skip to content

Commit

Permalink
Fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
syvb committed Mar 1, 2023
1 parent fbb781c commit 5f5dd75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
23 changes: 11 additions & 12 deletions extension/src/state_aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ impl MaterializedState {
}
}

fn as_string(self) -> String {
fn into_string(self) -> String {
match self {
Self::String(str) => str,
_ => panic!("MaterializedState::as_string called with non-string"),
_ => panic!("MaterializedState::into_string called with non-string"),
}
}
fn as_integer(self) -> i64 {
fn into_integer(self) -> i64 {
match self {
Self::Integer(int) => int,
_ => panic!("MaterializedState::as_integer called with non-integer"),
_ => panic!("MaterializedState::into_integer called with non-integer"),
}
}
}
Expand Down Expand Up @@ -129,7 +129,7 @@ impl StateEntry {
.expect("tried to stringify out-of-bounds state")
}

fn as_integer(self) -> i64 {
fn into_integer(self) -> i64 {
assert!(self.a == i64::MAX, "Tried to get non-integer state");
self.b
}
Expand Down Expand Up @@ -1075,7 +1075,7 @@ pub fn into_int_values<'a>(
agg.durations
.clone()
.into_iter()
.map(move |record| (record.state.as_integer(), record.duration.into()))
.map(move |record| (record.state.into_integer(), record.duration.into()))
.collect::<Vec<_>>()
.into_iter(), // make map panic now instead of at iteration time
)
Expand Down Expand Up @@ -1155,7 +1155,7 @@ fn state_int_timeline_inner<'a>(
.into_iter()
.map(move |record| {
(
record.state.as_integer(),
record.state.into_integer(),
TimestampTz::from(record.start_time),
TimestampTz::from(record.end_time),
)
Expand Down Expand Up @@ -1454,13 +1454,13 @@ fn state_at_inner<'a>(agg: StateAgg<'a>, point: i64) -> Option<MaterializedState
#[pg_extern(immutable, parallel_safe, name = "state_at")]
fn state_at<'a>(agg: StateAgg<'a>, point: TimestampTz) -> Option<String> {
agg.assert_str();
state_at_inner(agg, point.into()).map(MaterializedState::as_string)
state_at_inner(agg, point.into()).map(MaterializedState::into_string)
}

#[pg_extern(immutable, parallel_safe, name = "state_at_int")]
fn state_at_int<'a>(agg: StateAgg<'a>, point: TimestampTz) -> Option<i64> {
agg.assert_int();
state_at_inner(agg, point.into()).map(|s| MaterializedState::as_integer(s))
state_at_inner(agg, point.into()).map(MaterializedState::into_integer)
}

#[derive(Clone, Debug, Deserialize, Eq, FlatSerializable, PartialEq, Serialize)]
Expand Down Expand Up @@ -2388,9 +2388,8 @@ SELECT toolkit_experimental.duration_in('one', toolkit_experimental.compact_stat
trans_state_2.record(MaterializedState::Integer(444), 10005000);
let trans_state = state_agg::combine(Some(&trans_state_1), Some(&trans_state_2)).unwrap();

let buffer = state_agg::state_agg_serialize_fn_outer(
Inner::from(trans_state.clone()).internal().unwrap(),
);
let buffer =
state_agg::state_agg_serialize_fn_outer(Inner::from(trans_state).internal().unwrap());
let buffer = unsafe { pgx::varlena::varlena_to_byte_slice(buffer.0.cast_mut_ptr()) };

let expected = [
Expand Down
8 changes: 5 additions & 3 deletions extension/src/state_aggregate/accessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ macro_rules! state_function_accessor {
accessor: $accessor_name_string<'a>,
) -> $ret {
let state = MaterializedState::String(String::from_utf8_lossy(accessor.state_bytes.as_slice()).to_string());
#[allow(clippy::redundant_closure_call)] // needed to allow same macro for both uses
$inner(
agg.as_compact_state_agg(),
state,
Expand All @@ -321,6 +322,7 @@ macro_rules! state_function_accessor {
accessor: $accessor_name_int<'a>,
) -> $ret {
let state = MaterializedState::Integer(accessor.state);
#[allow(clippy::redundant_closure_call)] // needed to allow same macro for both uses
$inner(
agg.as_compact_state_agg(),
state,
Expand All @@ -342,7 +344,7 @@ state_function_accessor!(
AccessorStatePeriodsInt,
state_periods,
"state_periods",
(|agg, state| state_periods_inner(agg, state)),
state_periods_inner,
TableIterator<
'a,
(
Expand Down Expand Up @@ -485,11 +487,11 @@ macro_rules! state_at_accessor {
}
};
}
state_at_accessor!(AccessorStateAt, state_at, "state_at", String, as_string);
state_at_accessor!(AccessorStateAt, state_at, "state_at", String, into_string);
state_at_accessor!(
AccessorStateAtInt,
state_at_int,
"state_at_int",
i64,
as_integer
into_integer
);

0 comments on commit 5f5dd75

Please sign in to comment.