Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust nigthly & dependency fixes #15

Merged
merged 9 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apex-ctl/Cargo.toml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
4 changes: 2 additions & 2 deletions settings.toml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Loading