Skip to content

Commit

Permalink
Non-automatic clippy fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
TTWNO committed Jun 13, 2024
1 parent b51a257 commit 73760b7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 46 deletions.
53 changes: 27 additions & 26 deletions odilia/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,35 @@ pub async fn sr_event(
) -> eyre::Result<()> {
loop {
tokio::select! {
sr_event = sr_events.recv() => {
tracing::debug!("SR Event received");
match sr_event {
Some(ScreenReaderEvent::StructuralNavigation(dir, role)) => {
if let Err(e) = structural_navigation(&state, dir, role).await {
tracing::debug!(error = %e, "There was an error with the structural navigation call.");
} else {
tracing::debug!("Structural navigation successful!");
sr_event = sr_events.recv() => {
tracing::debug!("SR Event received");
match sr_event {
Some(ScreenReaderEvent::StructuralNavigation(dir, role)) => {
if let Err(e) = structural_navigation(&state, dir, role).await {
tracing::debug!(error = %e, "There was an error with the structural navigation call.");
} else {
tracing::debug!("Structural navigation successful!");
}
},
Some(ScreenReaderEvent::StopSpeech) => {
tracing::debug!("Stopping speech!");
state.stop_speech().await;
},
Some(ScreenReaderEvent::ChangeMode(new_sr_mode)) => {
tracing::debug!("Changing mode to {:?}", new_sr_mode);
if let Ok(mut sr_mode) = state.mode.lock() {
*sr_mode = new_sr_mode;
}
}
},
Some(ScreenReaderEvent::StopSpeech) => {
tracing::debug!("Stopping speech!");
state.stop_speech().await;
},
Some(ScreenReaderEvent::ChangeMode(new_sr_mode)) => {
tracing::debug!("Changing mode to {:?}", new_sr_mode);
let mut sr_mode = state.mode.lock().unwrap();
*sr_mode = new_sr_mode;
}
_ => { continue; }
};
continue;
}
() = shutdown.cancelled() => {
tracing::debug!("sr_event cancelled");
break;
_ => { continue; }
};
continue;
}
() = shutdown.cancelled() => {
tracing::debug!("sr_event cancelled");
break;
}
}
}
}
Ok(())
}
Expand Down
20 changes: 8 additions & 12 deletions odilia/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,13 @@ impl<E> TryFromState<Arc<ScreenReaderState>, E> for LastFocused {
type Error = OdiliaError;
type Future = Ready<Result<Self, Self::Error>>;
fn try_from_state(state: Arc<ScreenReaderState>, _event: E) -> Self::Future {
let ml = match state.accessible_history.lock() {
Ok(ml) => ml,
Err(_) => return err(OdiliaError::Generic("Could not get a lock on the history mutex. This is usually due to memory corruption or degradation and is a fatal error.".to_string())),
};
let last = match ml.iter().nth(0).cloned() {
Some(last) => last,
None => {
return err(OdiliaError::Generic(
"There are no previously focused items.".to_string(),
))
}
let Ok(ml) = state.accessible_history.lock() else {
return err(OdiliaError::Generic("Could not get a lock on the history mutex. This is usually due to memory corruption or degradation and is a fatal error.".to_string()));
};
let Some(last) = ml.iter().nth(0).cloned() else {
return err(OdiliaError::Generic(
"There are no previously focused items.".to_string(),
));
};
ok(LastFocused(last))
}
Expand Down Expand Up @@ -358,7 +354,7 @@ impl ScreenReaderState {
}
}

pub fn history_item<'a>(&self, index: usize) -> Option<AccessiblePrimitive> {
pub fn history_item(&self, index: usize) -> Option<AccessiblePrimitive> {
let history = self.accessible_history.lock().ok()?;
history.iter().nth(index).cloned()
}
Expand Down
2 changes: 2 additions & 0 deletions odilia/src/tower/from_state.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::module_name_repetitions)]

use futures::FutureExt;
use futures_concurrency::future::Join;

Expand Down
2 changes: 1 addition & 1 deletion odilia/src/tower/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ where
Poll::Ready(Ok(()))
}
fn call(&mut self, params: T) -> Self::Future {
self.handler.clone().call(params).map(|o| Ok(o))
self.handler.clone().call(params).map(Ok)
}
}
14 changes: 7 additions & 7 deletions odilia/src/tower/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,24 @@ impl Handlers {
<T as TryFromState<Arc<ScreenReaderState>, C>>::Future: Send,
<T as TryFromState<Arc<ScreenReaderState>, C>>::Error: Send,
{
let tflayer: TryIntoLayer<C, Command> = TryIntoLayer::new();
let tf2layer: AsyncTryIntoLayer<T, (Arc<ScreenReaderState>, C)> =
let try_cmd_layer: TryIntoLayer<C, Command> = TryIntoLayer::new();
let params_layer: AsyncTryIntoLayer<T, (Arc<ScreenReaderState>, C)> =
AsyncTryIntoLayer::new();
let state = Arc::clone(&self.state);
let state_layer: StateLayer<ScreenReaderState> = StateLayer::new(state);
// Service<T> -> Result<R, Infallible> -> unwrap -> R
// this is safe because we wrap the service in a Reuslt<R, Infallible> so that we can preserve
// any return type we want, including ones with no errors
// R -> Result<(), Error>
let ws1 = handler.into_service::<R>().map_result(|r| r.unwrap().into());
let hand_service = handler.into_service::<R>().map_result(|r| r.unwrap().into());
// Service(<Arc<S>, C>) -> T
let ws2 = tf2layer.layer(ws1);
let params_service = params_layer.layer(hand_service);
// Service<C> -> (Arc<S>, C)
let ws3 = state_layer.layer(ws2);
let state_service = state_layer.layer(params_service);
// Service<Command> -> C
let tfserv = tflayer.layer(ws3);
let try_cmd_service = try_cmd_layer.layer(state_service);
let dn = C::CTYPE;
let bs = BoxService::new(tfserv);
let bs = BoxService::new(try_cmd_service);
self.command.entry(dn).or_insert(bs);
Self { state: self.state, atspi: self.atspi, command: self.command }
}
Expand Down

0 comments on commit 73760b7

Please sign in to comment.