Skip to content

Commit 5750f97

Browse files
authored
Rust nigthly & dependency fixes (#15)
* Add rust-toolchain.toml file This file tells cargo (and other tools, like vscode rust-analyzer plugin) to use the nightly toolchain by default. This is needed to correctly open the project in vscode with rust-analyzer. We should probably fix a nigthly version, but for now leave it as a generic `nightly`. * Use feature(generic_associated_types) as in stable The feature(generic_associated_types) has been recently stabilized and does not need to be listed in the `#![feature(...)]` block. Also, move the `where` clauses on GAT impls to after the type assignment, taking advantage of a syntax change described here: rust-lang/rust#89122 * Update bitvec to 1.0.1 bitvec-0.22.3 depends on yanked funty-1.2.0 and no longer builds. Update to bitvec-1.0.1 as this is the most recent version. Change a few API calls as they have been renamed. Move the framebuffer BitArray size to a constant so that it is not repeated. * Fix a typo in settings.toml * Invoke `cargo fmt` on the whole workspace * Fix apex-ctl clap usage and update it Update clap to 4.0.26. Enable the `derive` feature to fix compilation. Change the derive attributes to work with newer version of clap. Drop apex_hardware::FareBuffer use. * Fix `debug` feature Make `src/render/debug.rs` buildable. * Fix `coindesk` section in `settings.toml` It was called `crypto`, but the provider is called `coindesk` instead. * fixup! Update bitvec to 1.0.1
1 parent 4f94270 commit 5750f97

File tree

21 files changed

+75
-90
lines changed

21 files changed

+75
-90
lines changed

apex-ctl/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77

88
[dependencies]
99
anyhow = "1.0.44"
10-
clap = "3.0.0-beta.5"
10+
clap = { version = "4.0.26", features = ["derive"] }
1111
log = "0.4.14"
1212
simplelog = "0.10.2"
1313
apex-hardware = { path = "../apex-hardware", features= ["usb"] }

apex-ctl/src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use anyhow::Result;
2-
use apex_hardware::{Device, FrameBuffer, USBDevice};
3-
use clap::Parser;
2+
use apex_hardware::{Device, USBDevice};
3+
use clap::{ArgAction, Parser, Subcommand};
44
use log::{info, LevelFilter};
55
use simplelog::{Config as LoggerConfig, SimpleLogger};
66

77
#[derive(Parser)]
88
#[clap(version = "1.0", author = "not-jan")]
99
struct Opts {
1010
/// A level of verbosity, and can be used multiple times
11-
#[clap(short, long, parse(from_occurrences))]
12-
verbose: i32,
13-
#[clap(subcommand)]
11+
#[arg(short, long, action = ArgAction::Count)]
12+
verbose: u8,
13+
#[command(subcommand)]
1414
subcmd: SubCommand,
1515
}
1616

17-
#[derive(Parser)]
17+
#[derive(Subcommand)]
1818
enum SubCommand {
1919
/// Clear the OLED screen
2020
Clear,

apex-engine/src/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl AsyncDevice for Engine {
7575
#[allow(clippy::needless_lifetimes)]
7676
fn draw<'this>(&'this mut self, display: &'this FrameBuffer) -> Self::DrawResult<'this> {
7777
async {
78-
let screen = display.framebuffer.as_buffer();
78+
let screen = display.framebuffer.as_raw_slice();
7979

8080
let event = GameEvent {
8181
game: GAME,

apex-engine/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#![feature(generic_associated_types, type_alias_impl_trait)]
1+
#![feature(type_alias_impl_trait)]
22
mod engine;
33
pub use engine::{Engine, HEARTBEAT, REMOVE_EVENT, REMOVE_GAME};

apex-hardware/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async = []
1212

1313
[dependencies]
1414
anyhow = "1.0.44"
15-
bitvec = "0.22.3"
15+
bitvec = "1.0.1"
1616
embedded-graphics = "0.7.1"
1717
hidapi = { version = "1.2.6", optional = true }
1818
num_enum = "0.5.4"

apex-hardware/src/device.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@ use embedded_graphics::{pixelcolor::BinaryColor, prelude::*};
44
#[cfg(feature = "async")]
55
use std::future::Future;
66

7+
const FB_SIZE: usize = 40 * 128 / 8 + 2;
8+
79
#[derive(Copy, Clone, Debug)]
810
pub struct FrameBuffer {
911
/// The framebuffer with one bit value per pixel.
1012
/// Two extra bytes are added, one for the header byte `0x61` and one for a
1113
/// trailing null byte. This is done to prevent superfluous copies when
1214
/// sending the image to a display device. The implementations of
1315
/// `Drawable` and `DrawTarget` take this quirk into account.
14-
pub framebuffer: BitArray<Msb0, [u8; 40 * 128 / 8 + 2]>,
16+
pub framebuffer: BitArray<[u8; FB_SIZE], Msb0>,
1517
}
1618

1719
impl Default for FrameBuffer {
1820
fn default() -> Self {
19-
let mut framebuffer = BitArray::<Msb0, [u8; 642]>::zeroed();
20-
framebuffer.as_mut_buffer()[0] = 0x61;
21+
let mut framebuffer = BitArray::<[u8; FB_SIZE], Msb0>::ZERO;
22+
framebuffer.as_raw_mut_slice()[0] = 0x61;
2123
FrameBuffer { framebuffer }
2224
}
2325
}
@@ -121,18 +123,15 @@ impl<T: Device> AsyncDevice for T
121123
where
122124
T: 'static,
123125
{
124-
type ClearResult<'a>
126+
type ClearResult<'a> = impl Future<Output = Result<()>> + 'a
125127
where
126-
Self: 'a,
127-
= impl Future<Output = Result<()>> + 'a;
128-
type DrawResult<'a>
128+
Self: 'a;
129+
type DrawResult<'a> = impl Future<Output = Result<()>> + 'a
129130
where
130-
Self: 'a,
131-
= impl Future<Output = Result<()>> + 'a;
132-
type ShutdownResult<'a>
131+
Self: 'a;
132+
type ShutdownResult<'a> = impl Future<Output = Result<()>> + 'a
133133
where
134-
Self: 'a,
135-
= impl Future<Output = Result<()>> + 'a;
134+
Self: 'a;
136135

137136
#[allow(clippy::needless_lifetimes)]
138137
fn draw<'this>(&'this mut self, display: &'this FrameBuffer) -> Self::DrawResult<'this> {

apex-hardware/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(generic_associated_types, type_alias_impl_trait)]
1+
#![feature(type_alias_impl_trait)]
22
mod device;
33
#[cfg(feature = "usb")]
44
mod usb;

apex-hardware/src/usb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Device for USBDevice {
6666
fn draw(&mut self, display: &FrameBuffer) -> Result<()> {
6767
Ok(self
6868
.handle
69-
.send_feature_report(display.framebuffer.as_buffer())?)
69+
.send_feature_report(display.framebuffer.as_raw_slice())?)
7070
}
7171

7272
fn clear(&mut self) -> Result<()> {

apex-mpris2/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(generic_associated_types, type_alias_impl_trait, async_iterator)]
1+
#![feature(type_alias_impl_trait, async_iterator)]
22
mod generated;
33
mod player;
44
pub use player::{Metadata, Player, MPRIS2};

apex-mpris2/src/player.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,18 @@ impl<'a> Player<'a> {
195195
impl<'a> AsyncPlayer for Player<'a> {
196196
type Metadata = Metadata;
197197

198-
type MetadataFuture<'b>
198+
type MetadataFuture<'b> = impl Future<Output = Result<Self::Metadata>> + 'b
199199
where
200-
Self: 'b,
201-
= impl Future<Output = Result<Self::Metadata>> + 'b;
202-
type NameFuture<'b>
200+
Self: 'b;
201+
type NameFuture<'b> = impl Future<Output = String> + 'b
203202
where
204-
Self: 'b,
205-
= impl Future<Output = String> + 'b;
206-
type PlaybackStatusFuture<'b>
203+
Self: 'b;
204+
type PlaybackStatusFuture<'b> = impl Future<Output = Result<PlaybackStatus>> + 'b
207205
where
208-
Self: 'b,
209-
= impl Future<Output = Result<PlaybackStatus>> + 'b;
210-
type PositionFuture<'b>
206+
Self: 'b;
207+
type PositionFuture<'b> = impl Future<Output = Result<i64>> + 'b
211208
where
212-
Self: 'b,
213-
= impl Future<Output = Result<i64>> + 'b;
209+
Self: 'b;
214210

215211
#[allow(clippy::needless_lifetimes)]
216212
fn metadata<'this>(&'this self) -> Self::MetadataFuture<'this> {

apex-music/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(generic_associated_types, type_alias_impl_trait)]
1+
#![feature(type_alias_impl_trait)]
22
mod player;
33
pub use player::{
44
AsyncMetadata, AsyncPlayer, Metadata, PlaybackStatus, Player, PlayerEvent, Progress,

apex-music/src/player.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub enum PlaybackStatus {
99
Playing,
1010
}
1111

12-
1312
#[derive(Clone, Debug)]
1413
pub enum PlayerEvent {
1514
Seeked,
@@ -72,22 +71,18 @@ pub trait AsyncPlayer {
7271
impl<T: Player + Sized> AsyncPlayer for T {
7372
type Metadata = <T as Player>::Metadata;
7473

75-
type MetadataFuture<'a>
74+
type MetadataFuture<'a> = impl Future<Output = Result<Self::Metadata>> + 'a
7675
where
77-
T: 'a,
78-
= impl Future<Output = Result<Self::Metadata>> + 'a;
79-
type NameFuture<'a>
76+
T: 'a;
77+
type NameFuture<'a> = impl Future<Output = String>
8078
where
81-
T: 'a,
82-
= impl Future<Output = String>;
83-
type PlaybackStatusFuture<'a>
79+
T: 'a;
80+
type PlaybackStatusFuture<'a> = impl Future<Output = Result<PlaybackStatus>>
8481
where
85-
T: 'a,
86-
= impl Future<Output = Result<PlaybackStatus>>;
87-
type PositionFuture<'a>
82+
T: 'a;
83+
type PositionFuture<'a> = impl Future<Output = Result<i64>>
8884
where
89-
T: 'a,
90-
= impl Future<Output = Result<i64>>;
85+
T: 'a;
9186

9287
#[allow(clippy::needless_lifetimes)]
9388
fn metadata<'this>(&'this self) -> Self::MetadataFuture<'this> {
@@ -137,18 +132,15 @@ pub trait AsyncMetadata {
137132

138133
/// Blanket implementation for non-async Metadata sources
139134
impl<T: Metadata + Sized> AsyncMetadata for T {
140-
type ArtistsFuture<'a>
135+
type ArtistsFuture<'a> = impl Future<Output = Result<String>> + 'a
141136
where
142-
T: 'a,
143-
= impl Future<Output = Result<String>> + 'a;
144-
type LengthFuture<'a>
137+
T: 'a;
138+
type LengthFuture<'a> = impl Future<Output = Result<i64>> + 'a
145139
where
146-
T: 'a,
147-
= impl Future<Output = Result<i64>> + 'a;
148-
type TitleFuture<'a>
140+
T: 'a;
141+
type TitleFuture<'a> = impl Future<Output = Result<String>> + 'a
149142
where
150-
T: 'a,
151-
= impl Future<Output = Result<String>> + 'a;
143+
T: 'a;
152144

153145
#[allow(clippy::needless_lifetimes)]
154146
fn title<'this>(&'this self) -> Self::TitleFuture<'this> {

apex-windows/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(generic_associated_types, type_alias_impl_trait,async_iterator)]
1+
#![feature(type_alias_impl_trait, async_iterator)]
22
mod music;
3-
pub use music::Player;
4-
pub use music::Metadata;
3+
pub use music::{Metadata, Player};

apex-windows/src/music.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use anyhow::{anyhow, Result};
22
use apex_music::{AsyncPlayer, Metadata as MetadataTrait, PlaybackStatus, PlayerEvent, Progress};
3-
use std::future::Future;
43
use futures_core::stream::Stream;
4+
use std::future::Future;
55

6-
use std::time::Duration;
76
use async_stream::stream;
7+
use std::time::Duration;
88
use tokio::time::MissedTickBehavior;
99
use windows::Media::{
1010
Control,
@@ -82,7 +82,7 @@ impl Player {
8282
pub async fn stream(&self) -> Result<impl Stream<Item = PlayerEvent>> {
8383
let mut timer = tokio::time::interval(Duration::from_millis(100));
8484
timer.set_missed_tick_behavior(MissedTickBehavior::Skip);
85-
Ok(stream!{
85+
Ok(stream! {
8686
loop {
8787
timer.tick().await;
8888
yield PlayerEvent::Timer;
@@ -93,34 +93,29 @@ impl Player {
9393
impl AsyncPlayer for Player {
9494
type Metadata = Metadata;
9595

96-
type MetadataFuture<'b>
96+
type MetadataFuture<'b> = impl Future<Output = Result<Self::Metadata>> + 'b
9797
where
98-
Self: 'b,
99-
= impl Future<Output = Result<Self::Metadata>> + 'b;
100-
type NameFuture<'b>
98+
Self: 'b;
99+
type NameFuture<'b> = impl Future<Output = String> + 'b
101100
where
102-
Self: 'b,
103-
= impl Future<Output = String> + 'b;
104-
type PlaybackStatusFuture<'b>
101+
Self: 'b;
102+
type PlaybackStatusFuture<'b> = impl Future<Output = Result<PlaybackStatus>> + 'b
105103
where
106-
Self: 'b,
107-
= impl Future<Output = Result<PlaybackStatus>> + 'b;
108-
type PositionFuture<'b>
104+
Self: 'b;
105+
type PositionFuture<'b> = impl Future<Output = Result<i64>> + 'b
109106
where
110-
Self: 'b,
111-
= impl Future<Output = Result<i64>> + 'b;
107+
Self: 'b;
108+
112109
#[allow(clippy::needless_lifetimes)]
113110
fn metadata<'this>(&'this self) -> Self::MetadataFuture<'this> {
114111
async {
115112
let session = self.media_properties().await?;
116113
let title = session.Title()?.to_string_lossy();
117114
let artists = session.Artist()?.to_string_lossy();
118-
Ok(Metadata {
119-
title,
120-
artists
121-
})
115+
Ok(Metadata { title, artists })
122116
}
123117
}
118+
124119
#[allow(clippy::needless_lifetimes)]
125120
fn playback_status<'this>(&'this self) -> Self::PlaybackStatusFuture<'this> {
126121
async {
@@ -146,12 +141,14 @@ impl AsyncPlayer for Player {
146141
})
147142
}
148143
}
144+
149145
#[allow(clippy::needless_lifetimes)]
150146
fn name<'this>(&'this self) -> Self::NameFuture<'this> {
151147
// There might be a Windows API to find the name of the player but the user most
152148
// likely will never see this anyway
153149
async { String::from("windows-api") }
154150
}
151+
155152
#[allow(clippy::needless_lifetimes)]
156153
fn position<'this>(&'this self) -> Self::PositionFuture<'this> {
157154
// TODO: Find the API for this?

rust-toolchain.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "nightly"

settings.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ enabled = true
33
# Set this to the highest priority so it will start with the clock
44
# priority = 1
55
# Enables a twelve hour clock instead of the 24hr one
6-
# Defaults to your lcoal format if unset
6+
# Defaults to your local format if unset
77
# twelve_hour = false
88

99
[mpris2]
@@ -12,7 +12,7 @@ enabled = true
1212
# You can check what to put here by using tools like D-Feet
1313
# preferred_player = "Lollypop"
1414

15-
[crypto]
15+
[coindesk]
1616
enabled = true
1717
# Valid choices are "gbp", "usd" and "eur"
1818
# Default is USD

src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![allow(incomplete_features)]
22
#![feature(
3-
generic_associated_types,
43
type_alias_impl_trait,
54
try_blocks,
65
const_fn_floating_point_arithmetic,

src/providers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ pub(crate) mod clock;
22
#[cfg(feature = "crypto")]
33
pub(crate) mod coindesk;
44
#[cfg(any(feature = "dbus-support", target_os = "windows"))]
5-
pub(crate) mod music;
5+
pub(crate) mod music;

src/render/debug.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::render::{
44
};
55
use anyhow::Result;
66
use async_stream::try_stream;
7+
use config::Config;
78
use embedded_graphics::{
89
pixelcolor::BinaryColor,
910
prelude::Point,
@@ -22,7 +23,7 @@ use tokio::{
2223
static PROVIDER_INIT: fn(&Config) -> Result<Box<dyn ContentWrapper>> = register_callback;
2324

2425
#[allow(clippy::unnecessary_wraps)]
25-
fn register_callback() -> Result<Box<dyn ContentWrapper>> {
26+
fn register_callback(_config: &Config) -> Result<Box<dyn ContentWrapper>> {
2627
info!("Registering dummy display source.");
2728
let provider = Box::new(DummyProvider {});
2829
Ok(provider)

src/render/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
22

3-
use apex_hardware::FrameBuffer;
3+
pub use apex_hardware::FrameBuffer;
44
use futures_core::Stream;
55

66
pub trait ContentProvider {

0 commit comments

Comments
 (0)