Skip to content

Commit a7982bd

Browse files
committed
chore: clippy nursery
1 parent e4211cd commit a7982bd

96 files changed

Lines changed: 440 additions & 427 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
shell: bash
4343
run: |
4444
cargo fmt --all --check
45-
cargo clippy -- --no-deps -Dclippy::pedantic -Dwarnings
45+
cargo clippy -- --no-deps -Dclippy::pedantic -Dclippy::nursery -Dwarnings
4646
4747
- uses: pnpm/action-setup@v4
4848
with:

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ uniffi_bindgen = "=0.29.4"
3333

3434
[workspace.lints.clippy]
3535
pedantic = "warn"
36+
nursery = "warn"
3637

3738
[workspace.lints.rust]
3839
unsafe_code = "forbid"

Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ check:
1313
@echo '{{ style("command") }}check:{{ NORMAL }}'
1414
cargo fmt --all --check
1515
cargo check --all-features
16-
cargo clippy --all-targets -- --no-deps -Dclippy::pedantic -Dwarnings
16+
cargo clippy --all-targets -- --no-deps -Dclippy::pedantic -Dclippy::nursery -Dwarnings
1717

1818
# Clean build artefacts in the root workspace and all examples
1919
clean:

crux_core/src/bridge/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ pub trait FfiFormat: Debug + 'static {
3838
fn deserialize<'de, T: Deserialize<'de>>(bytes: &'de [u8]) -> Result<T, Self::Error>;
3939
}
4040

41-
/// Request for a side-effect passed from the Core to the Shell. The `EffectId` links
42-
/// the `Request` with the corresponding call to [`Core::resolve`] to pass the data back
41+
/// Request for a side-effect passed from the Core to the Shell.
42+
///
43+
/// The `EffectId` links the `Request` with the corresponding call to [`Core::resolve`] to pass the data back
4344
/// to the [`App::update`] function (wrapped in the event provided to the capability originating the effect).
4445
// used in docs/internals/bridge.md
4546
// ANCHOR: request

crux_core/src/bridge/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<T: FfiFormat> ResolveRegistry<T> {
6262

6363
let resolved = entry.resolve(response);
6464

65-
if let ResolveSerialized::Never = entry {
65+
if matches!(entry, ResolveSerialized::Never) {
6666
registry_lock.remove(id.0 as usize);
6767
}
6868

crux_core/src/bridge/request_serde.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ pub enum ResolveSerialized<T: FfiFormat> {
2727
impl<T: FfiFormat> ResolveSerialized<T> {
2828
pub(crate) fn resolve(&mut self, response: &[u8]) -> Result<(), BridgeError<T>> {
2929
match self {
30-
ResolveSerialized::Never => Err(BridgeError::ProcessResponse(ResolveError::Never)),
31-
ResolveSerialized::Many(f) => f(response),
32-
ResolveSerialized::Once(_) => {
30+
Self::Never => Err(BridgeError::ProcessResponse(ResolveError::Never)),
31+
Self::Many(f) => f(response),
32+
Self::Once(_) => {
3333
// The resolve has been used, turn it into a Never
34-
let ResolveSerialized::Once(f) = std::mem::replace(self, ResolveSerialized::Never)
35-
else {
34+
let Self::Once(f) = std::mem::replace(self, Self::Never) else {
3635
unreachable!("already resolved");
3736
};
3837

@@ -77,13 +76,13 @@ impl<Out> RequestHandle<Out> {
7776
Out: 'static,
7877
{
7978
match self {
80-
RequestHandle::Never => ResolveSerialized::Never,
81-
RequestHandle::Once(resolve) => ResolveSerialized::Once(Box::new(move |response| {
79+
Self::Never => ResolveSerialized::Never,
80+
Self::Once(resolve) => ResolveSerialized::Once(Box::new(move |response| {
8281
let out = func(response)?;
8382
resolve(out);
8483
Ok(())
8584
})),
86-
RequestHandle::Many(resolve) => ResolveSerialized::Many(Box::new(move |response| {
85+
Self::Many(resolve) => ResolveSerialized::Many(Box::new(move |response| {
8786
let out = func(response)?;
8887
resolve(out).map_err(|()| BridgeError::ProcessResponse(ResolveError::FinishedMany))
8988
})),

crux_core/src/command/builder.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ where
3030
{
3131
let make_task = Box::new(make_task);
3232

33-
NotificationBuilder { make_task }
33+
Self { make_task }
3434
}
3535

3636
/// Convert the [`NotificationBuilder`] into a future to use in an async context
@@ -53,7 +53,7 @@ where
5353
Task: Future<Output = ()> + Send + 'static,
5454
{
5555
fn from(value: NotificationBuilder<Effect, Event, Task>) -> Self {
56-
Command::new(|ctx| value.into_future(ctx))
56+
Self::new(|ctx| value.into_future(ctx))
5757
}
5858
}
5959

@@ -75,14 +75,14 @@ where
7575
{
7676
let make_task = Box::new(make_task);
7777

78-
RequestBuilder { make_task }
78+
Self { make_task }
7979
}
8080

8181
pub fn map<F, U>(self, map: F) -> RequestBuilder<Effect, Event, impl Future<Output = U>>
8282
where
8383
F: FnOnce(T) -> U + Send + 'static,
8484
{
85-
RequestBuilder::new(|ctx| self.into_future(ctx.clone()).map(map))
85+
RequestBuilder::new(|ctx| self.into_future(ctx).map(map))
8686
}
8787

8888
/// Chain a [`NotificationBuilder`] to run after completion of this one,
@@ -409,7 +409,7 @@ where
409409
{
410410
let make_task = Box::new(make_task);
411411

412-
StreamBuilder {
412+
Self {
413413
make_stream: make_task,
414414
}
415415
}
@@ -418,7 +418,7 @@ where
418418
where
419419
F: FnMut(T) -> U + Send + 'static,
420420
{
421-
StreamBuilder::new(|ctx| self.into_stream(ctx.clone()).map(map))
421+
StreamBuilder::new(|ctx| self.into_stream(ctx).map(map))
422422
}
423423

424424
/// Chain a [`RequestBuilder`] to run after completion of this [`StreamBuilder`],

crux_core/src/command/context.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<Effect, Event> CommandContext<Effect, Event> {
145145
// ANCHOR: spawn
146146
pub fn spawn<F, Fut>(&self, make_future: F) -> JoinHandle
147147
where
148-
F: FnOnce(CommandContext<Effect, Event>) -> Fut,
148+
F: FnOnce(Self) -> Fut,
149149
Fut: Future<Output = ()> + Send + 'static,
150150
{
151151
let (sender, receiver) = crossbeam_channel::unbounded();
@@ -185,22 +185,21 @@ impl<T: Unpin + Send> ShellStream<T> {
185185
send_request: impl FnOnce() + Send + 'static,
186186
output_receiver: mpsc::UnboundedReceiver<T>,
187187
) -> Self {
188-
ShellStream::ReadyToSend(Box::new(send_request), output_receiver)
188+
Self::ReadyToSend(Box::new(send_request), output_receiver)
189189
}
190190

191191
fn send(&mut self) {
192192
// Since neither part is Clone, we'll need to do an Indiana Jones
193193

194194
// 1. take items out of self
195-
let dummy = ShellStream::Sent(mpsc::unbounded().1);
196-
let ShellStream::ReadyToSend(send_request, output_receiver) =
197-
std::mem::replace(self, dummy)
195+
let dummy = Self::Sent(mpsc::unbounded().1);
196+
let Self::ReadyToSend(send_request, output_receiver) = std::mem::replace(self, dummy)
198197
else {
199198
unreachable!("cannot send");
200199
};
201200

202201
// 2. replace self with with a Sent using the original receiver
203-
*self = ShellStream::Sent(output_receiver);
202+
*self = Self::Sent(output_receiver);
204203

205204
send_request();
206205
}
@@ -211,15 +210,15 @@ impl<T: Unpin + Send> Stream for ShellStream<T> {
211210

212211
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
213212
match *self {
214-
ShellStream::ReadyToSend(_, ref mut output_receiver) => {
213+
Self::ReadyToSend(_, ref mut output_receiver) => {
215214
let poll = pin!(output_receiver).poll_next(cx);
216215
assert!(matches!(poll, Poll::Pending)); // we have not sent the request yet
217216

218217
self.send();
219218

220219
Poll::Pending
221220
}
222-
ShellStream::Sent(ref mut output_receiver) => pin!(output_receiver).poll_next(cx),
221+
Self::Sent(ref mut output_receiver) => pin!(output_receiver).poll_next(cx),
223222
}
224223
}
225224
}

crux_core/src/command/executor.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use futures::task::AtomicWaker;
1515

1616
use std::sync::Arc;
1717

18-
#[derive(Clone, Copy, Debug, PartialEq)]
19-
pub(crate) struct TaskId(pub(crate) usize);
18+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
19+
pub struct TaskId(pub(crate) usize);
2020

2121
// ANCHOR: task
22-
pub(crate) struct Task {
22+
pub struct Task {
2323
// Used to wake the join handle when the task concludes
2424
pub(crate) join_handle_wakers: Receiver<Waker>,
2525
// Set to true when the task finishes, used by the join handle
@@ -52,7 +52,7 @@ impl Task {
5252
// Waking a task also wakes the command itself, if it is being used as a Stream
5353
// inside another Command (or hosted with a CommandSink)
5454
// ANCHOR: command_waker
55-
pub(crate) struct CommandWaker {
55+
pub struct CommandWaker {
5656
pub(crate) task_id: TaskId,
5757
pub(crate) ready_queue: Sender<TaskId>,
5858
// Waker for the executor running this command as a Stream.
@@ -139,8 +139,8 @@ impl Future for JoinHandle {
139139
}
140140
}
141141

142-
#[derive(Debug, PartialEq)]
143-
pub(crate) enum TaskState {
142+
#[derive(Debug, PartialEq, Eq)]
143+
pub enum TaskState {
144144
Missing,
145145
Suspended,
146146
Completed,

0 commit comments

Comments
 (0)