Skip to content

Commit

Permalink
Rust nigthly & dependency fixes (#15)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
BigBigos committed Nov 29, 2022
1 parent 4f94270 commit 5750f97
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 90 deletions.
2 changes: 1 addition & 1 deletion apex-ctl/Cargo.toml
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0.44"
clap = "3.0.0-beta.5"
clap = { version = "4.0.26", features = ["derive"] }
log = "0.4.14"
simplelog = "0.10.2"
apex-hardware = { path = "../apex-hardware", features= ["usb"] }
12 changes: 6 additions & 6 deletions apex-ctl/src/main.rs
@@ -1,20 +1,20 @@
use anyhow::Result;
use apex_hardware::{Device, FrameBuffer, USBDevice};
use clap::Parser;
use apex_hardware::{Device, USBDevice};
use clap::{ArgAction, Parser, Subcommand};
use log::{info, LevelFilter};
use simplelog::{Config as LoggerConfig, SimpleLogger};

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

#[derive(Parser)]
#[derive(Subcommand)]
enum SubCommand {
/// Clear the OLED screen
Clear,
Expand Down
2 changes: 1 addition & 1 deletion apex-engine/src/engine.rs
Expand Up @@ -75,7 +75,7 @@ impl AsyncDevice for Engine {
#[allow(clippy::needless_lifetimes)]
fn draw<'this>(&'this mut self, display: &'this FrameBuffer) -> Self::DrawResult<'this> {
async {
let screen = display.framebuffer.as_buffer();
let screen = display.framebuffer.as_raw_slice();

let event = GameEvent {
game: GAME,
Expand Down
2 changes: 1 addition & 1 deletion apex-engine/src/lib.rs
@@ -1,3 +1,3 @@
#![feature(generic_associated_types, type_alias_impl_trait)]
#![feature(type_alias_impl_trait)]
mod engine;
pub use engine::{Engine, HEARTBEAT, REMOVE_EVENT, REMOVE_GAME};
2 changes: 1 addition & 1 deletion apex-hardware/Cargo.toml
Expand Up @@ -12,7 +12,7 @@ async = []

[dependencies]
anyhow = "1.0.44"
bitvec = "0.22.3"
bitvec = "1.0.1"
embedded-graphics = "0.7.1"
hidapi = { version = "1.2.6", optional = true }
num_enum = "0.5.4"
23 changes: 11 additions & 12 deletions apex-hardware/src/device.rs
Expand Up @@ -4,20 +4,22 @@ use embedded_graphics::{pixelcolor::BinaryColor, prelude::*};
#[cfg(feature = "async")]
use std::future::Future;

const FB_SIZE: usize = 40 * 128 / 8 + 2;

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

impl Default for FrameBuffer {
fn default() -> Self {
let mut framebuffer = BitArray::<Msb0, [u8; 642]>::zeroed();
framebuffer.as_mut_buffer()[0] = 0x61;
let mut framebuffer = BitArray::<[u8; FB_SIZE], Msb0>::ZERO;
framebuffer.as_raw_mut_slice()[0] = 0x61;
FrameBuffer { framebuffer }
}
}
Expand Down Expand Up @@ -121,18 +123,15 @@ impl<T: Device> AsyncDevice for T
where
T: 'static,
{
type ClearResult<'a>
type ClearResult<'a> = impl Future<Output = Result<()>> + 'a
where
Self: 'a,
= impl Future<Output = Result<()>> + 'a;
type DrawResult<'a>
Self: 'a;
type DrawResult<'a> = impl Future<Output = Result<()>> + 'a
where
Self: 'a,
= impl Future<Output = Result<()>> + 'a;
type ShutdownResult<'a>
Self: 'a;
type ShutdownResult<'a> = impl Future<Output = Result<()>> + 'a
where
Self: 'a,
= impl Future<Output = Result<()>> + 'a;
Self: 'a;

#[allow(clippy::needless_lifetimes)]
fn draw<'this>(&'this mut self, display: &'this FrameBuffer) -> Self::DrawResult<'this> {
Expand Down
2 changes: 1 addition & 1 deletion apex-hardware/src/lib.rs
@@ -1,4 +1,4 @@
#![feature(generic_associated_types, type_alias_impl_trait)]
#![feature(type_alias_impl_trait)]
mod device;
#[cfg(feature = "usb")]
mod usb;
Expand Down
2 changes: 1 addition & 1 deletion apex-hardware/src/usb.rs
Expand Up @@ -66,7 +66,7 @@ impl Device for USBDevice {
fn draw(&mut self, display: &FrameBuffer) -> Result<()> {
Ok(self
.handle
.send_feature_report(display.framebuffer.as_buffer())?)
.send_feature_report(display.framebuffer.as_raw_slice())?)
}

fn clear(&mut self) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion apex-mpris2/src/lib.rs
@@ -1,4 +1,4 @@
#![feature(generic_associated_types, type_alias_impl_trait, async_iterator)]
#![feature(type_alias_impl_trait, async_iterator)]
mod generated;
mod player;
pub use player::{Metadata, Player, MPRIS2};
20 changes: 8 additions & 12 deletions apex-mpris2/src/player.rs
Expand Up @@ -195,22 +195,18 @@ impl<'a> Player<'a> {
impl<'a> AsyncPlayer for Player<'a> {
type Metadata = Metadata;

type MetadataFuture<'b>
type MetadataFuture<'b> = impl Future<Output = Result<Self::Metadata>> + 'b
where
Self: 'b,
= impl Future<Output = Result<Self::Metadata>> + 'b;
type NameFuture<'b>
Self: 'b;
type NameFuture<'b> = impl Future<Output = String> + 'b
where
Self: 'b,
= impl Future<Output = String> + 'b;
type PlaybackStatusFuture<'b>
Self: 'b;
type PlaybackStatusFuture<'b> = impl Future<Output = Result<PlaybackStatus>> + 'b
where
Self: 'b,
= impl Future<Output = Result<PlaybackStatus>> + 'b;
type PositionFuture<'b>
Self: 'b;
type PositionFuture<'b> = impl Future<Output = Result<i64>> + 'b
where
Self: 'b,
= impl Future<Output = Result<i64>> + 'b;
Self: 'b;

#[allow(clippy::needless_lifetimes)]
fn metadata<'this>(&'this self) -> Self::MetadataFuture<'this> {
Expand Down
2 changes: 1 addition & 1 deletion apex-music/src/lib.rs
@@ -1,4 +1,4 @@
#![feature(generic_associated_types, type_alias_impl_trait)]
#![feature(type_alias_impl_trait)]
mod player;
pub use player::{
AsyncMetadata, AsyncPlayer, Metadata, PlaybackStatus, Player, PlayerEvent, Progress,
Expand Down
36 changes: 14 additions & 22 deletions apex-music/src/player.rs
Expand Up @@ -9,7 +9,6 @@ pub enum PlaybackStatus {
Playing,
}


#[derive(Clone, Debug)]
pub enum PlayerEvent {
Seeked,
Expand Down Expand Up @@ -72,22 +71,18 @@ pub trait AsyncPlayer {
impl<T: Player + Sized> AsyncPlayer for T {
type Metadata = <T as Player>::Metadata;

type MetadataFuture<'a>
type MetadataFuture<'a> = impl Future<Output = Result<Self::Metadata>> + 'a
where
T: 'a,
= impl Future<Output = Result<Self::Metadata>> + 'a;
type NameFuture<'a>
T: 'a;
type NameFuture<'a> = impl Future<Output = String>
where
T: 'a,
= impl Future<Output = String>;
type PlaybackStatusFuture<'a>
T: 'a;
type PlaybackStatusFuture<'a> = impl Future<Output = Result<PlaybackStatus>>
where
T: 'a,
= impl Future<Output = Result<PlaybackStatus>>;
type PositionFuture<'a>
T: 'a;
type PositionFuture<'a> = impl Future<Output = Result<i64>>
where
T: 'a,
= impl Future<Output = Result<i64>>;
T: 'a;

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

/// Blanket implementation for non-async Metadata sources
impl<T: Metadata + Sized> AsyncMetadata for T {
type ArtistsFuture<'a>
type ArtistsFuture<'a> = impl Future<Output = Result<String>> + 'a
where
T: 'a,
= impl Future<Output = Result<String>> + 'a;
type LengthFuture<'a>
T: 'a;
type LengthFuture<'a> = impl Future<Output = Result<i64>> + 'a
where
T: 'a,
= impl Future<Output = Result<i64>> + 'a;
type TitleFuture<'a>
T: 'a;
type TitleFuture<'a> = impl Future<Output = Result<String>> + 'a
where
T: 'a,
= impl Future<Output = Result<String>> + 'a;
T: 'a;

#[allow(clippy::needless_lifetimes)]
fn title<'this>(&'this self) -> Self::TitleFuture<'this> {
Expand Down
5 changes: 2 additions & 3 deletions apex-windows/src/lib.rs
@@ -1,4 +1,3 @@
#![feature(generic_associated_types, type_alias_impl_trait,async_iterator)]
#![feature(type_alias_impl_trait, async_iterator)]
mod music;
pub use music::Player;
pub use music::Metadata;
pub use music::{Metadata, Player};
35 changes: 16 additions & 19 deletions apex-windows/src/music.rs
@@ -1,10 +1,10 @@
use anyhow::{anyhow, Result};
use apex_music::{AsyncPlayer, Metadata as MetadataTrait, PlaybackStatus, PlayerEvent, Progress};
use std::future::Future;
use futures_core::stream::Stream;
use std::future::Future;

use std::time::Duration;
use async_stream::stream;
use std::time::Duration;
use tokio::time::MissedTickBehavior;
use windows::Media::{
Control,
Expand Down Expand Up @@ -82,7 +82,7 @@ impl Player {
pub async fn stream(&self) -> Result<impl Stream<Item = PlayerEvent>> {
let mut timer = tokio::time::interval(Duration::from_millis(100));
timer.set_missed_tick_behavior(MissedTickBehavior::Skip);
Ok(stream!{
Ok(stream! {
loop {
timer.tick().await;
yield PlayerEvent::Timer;
Expand All @@ -93,34 +93,29 @@ impl Player {
impl AsyncPlayer for Player {
type Metadata = Metadata;

type MetadataFuture<'b>
type MetadataFuture<'b> = impl Future<Output = Result<Self::Metadata>> + 'b
where
Self: 'b,
= impl Future<Output = Result<Self::Metadata>> + 'b;
type NameFuture<'b>
Self: 'b;
type NameFuture<'b> = impl Future<Output = String> + 'b
where
Self: 'b,
= impl Future<Output = String> + 'b;
type PlaybackStatusFuture<'b>
Self: 'b;
type PlaybackStatusFuture<'b> = impl Future<Output = Result<PlaybackStatus>> + 'b
where
Self: 'b,
= impl Future<Output = Result<PlaybackStatus>> + 'b;
type PositionFuture<'b>
Self: 'b;
type PositionFuture<'b> = impl Future<Output = Result<i64>> + 'b
where
Self: 'b,
= impl Future<Output = Result<i64>> + 'b;
Self: 'b;

#[allow(clippy::needless_lifetimes)]
fn metadata<'this>(&'this self) -> Self::MetadataFuture<'this> {
async {
let session = self.media_properties().await?;
let title = session.Title()?.to_string_lossy();
let artists = session.Artist()?.to_string_lossy();
Ok(Metadata {
title,
artists
})
Ok(Metadata { title, artists })
}
}

#[allow(clippy::needless_lifetimes)]
fn playback_status<'this>(&'this self) -> Self::PlaybackStatusFuture<'this> {
async {
Expand All @@ -146,12 +141,14 @@ impl AsyncPlayer for Player {
})
}
}

#[allow(clippy::needless_lifetimes)]
fn name<'this>(&'this self) -> Self::NameFuture<'this> {
// There might be a Windows API to find the name of the player but the user most
// likely will never see this anyway
async { String::from("windows-api") }
}

#[allow(clippy::needless_lifetimes)]
fn position<'this>(&'this self) -> Self::PositionFuture<'this> {
// TODO: Find the API for this?
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
4 changes: 2 additions & 2 deletions settings.toml
Expand Up @@ -3,7 +3,7 @@ enabled = true
# Set this to the highest priority so it will start with the clock
# priority = 1
# Enables a twelve hour clock instead of the 24hr one
# Defaults to your lcoal format if unset
# Defaults to your local format if unset
# twelve_hour = false

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

[crypto]
[coindesk]
enabled = true
# Valid choices are "gbp", "usd" and "eur"
# Default is USD
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
@@ -1,6 +1,5 @@
#![allow(incomplete_features)]
#![feature(
generic_associated_types,
type_alias_impl_trait,
try_blocks,
const_fn_floating_point_arithmetic,
Expand Down
2 changes: 1 addition & 1 deletion src/providers/mod.rs
Expand Up @@ -2,4 +2,4 @@ pub(crate) mod clock;
#[cfg(feature = "crypto")]
pub(crate) mod coindesk;
#[cfg(any(feature = "dbus-support", target_os = "windows"))]
pub(crate) mod music;
pub(crate) mod music;
3 changes: 2 additions & 1 deletion src/render/debug.rs
Expand Up @@ -4,6 +4,7 @@ use crate::render::{
};
use anyhow::Result;
use async_stream::try_stream;
use config::Config;
use embedded_graphics::{
pixelcolor::BinaryColor,
prelude::Point,
Expand All @@ -22,7 +23,7 @@ use tokio::{
static PROVIDER_INIT: fn(&Config) -> Result<Box<dyn ContentWrapper>> = register_callback;

#[allow(clippy::unnecessary_wraps)]
fn register_callback() -> Result<Box<dyn ContentWrapper>> {
fn register_callback(_config: &Config) -> Result<Box<dyn ContentWrapper>> {
info!("Registering dummy display source.");
let provider = Box::new(DummyProvider {});
Ok(provider)
Expand Down
2 changes: 1 addition & 1 deletion src/render/display.rs
@@ -1,6 +1,6 @@
use anyhow::Result;

use apex_hardware::FrameBuffer;
pub use apex_hardware::FrameBuffer;
use futures_core::Stream;

pub trait ContentProvider {
Expand Down

0 comments on commit 5750f97

Please sign in to comment.