Skip to content

Commit

Permalink
fix const_trait usage, CI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
boozook committed Jul 12, 2024
1 parent bf9caaa commit 0a71b9f
Show file tree
Hide file tree
Showing 23 changed files with 109 additions and 112 deletions.
24 changes: 2 additions & 22 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -475,30 +475,10 @@ jobs:

- name: Check
id: check
continue-on-error: true
run: >-
cargo fmt --all -- --check ||
(echo "::error::Rust format error." && exit 1)
- name: Format
id: format
if: steps.check.outcome == 'failure'
run: cargo fmt --all

- name: Suggestions
uses: reviewdog/action-suggester@v1
with:
filter_mode: diff_context
fail_on_error: false
tool_name: Rustfmt
cleanup: false

# - name: Post Check
# if: steps.check.outcome == 'failure'
# run: exit 1
run: cargo fmt --all -- --check

clippy:
name: Clippy
name: Clippy + fmt suggestions
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
defaults:
run:
Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/color/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playdate-color"
version = "0.2.4"
version = "0.2.5"
readme = "README.md"
description = "Color extension for Playdate API"
keywords = ["playdate", "sdk", "api", "gamedev"]
Expand Down
50 changes: 37 additions & 13 deletions api/color/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ impl<'t> TryFrom<LCDColor> for Color<'t>

fn try_from(color: LCDColor) -> Result<Self, Self::Error> {
match color {
0 => Ok(Self::Solid(LCDSolidColor::Black())),
1 => Ok(Self::Solid(LCDSolidColor::White())),
2 => Ok(Self::Solid(LCDSolidColor::Clear())),
3 => Ok(Self::Solid(LCDSolidColor::XOR())),
0 => Ok(Self::Solid(LCDSolidColor::BLACK)),
1 => Ok(Self::Solid(LCDSolidColor::WHITE)),
2 => Ok(Self::Solid(LCDSolidColor::CLEAR)),
3 => Ok(Self::Solid(<LCDSolidColor as LCDColorConst>::XOR)),
color => {
NonNull::new(color as *mut LCDPattern).ok_or(NullPtrError)
.map(|nn| Self::Pattern(unsafe { nn.as_ref() }))
Expand All @@ -63,7 +63,8 @@ impl<'t> From<&'t LCDPattern> for Color<'t> {
}


#[const_trait]
// TODO: LCDColorExt should be const_trait
#[deprecated = "Useless until const_trait is experimental and incomplete. Use LCDColorConst instead."]
pub trait LCDColorExt {
#![allow(non_snake_case)]
fn White() -> Self;
Expand All @@ -72,30 +73,53 @@ pub trait LCDColorExt {
fn XOR() -> Self;
}

impl const LCDColorExt for LCDColor {
#[allow(deprecated)]
impl LCDColorExt for LCDColor {
#![allow(non_snake_case)]
fn White() -> Self { LCDSolidColor::kColorWhite as Self }
fn Black() -> Self { LCDSolidColor::kColorBlack as Self }
fn Clear() -> Self { LCDSolidColor::kColorClear as Self }
fn XOR() -> Self { LCDSolidColor::kColorXOR as Self }
}

impl const LCDColorExt for LCDSolidColor {
#[allow(deprecated)]
impl LCDColorExt for LCDSolidColor {
#![allow(non_snake_case)]
fn White() -> Self { LCDSolidColor::kColorWhite }
fn Black() -> Self { LCDSolidColor::kColorBlack }
fn Clear() -> Self { LCDSolidColor::kColorClear }
fn XOR() -> Self { LCDSolidColor::kColorXOR }
}

pub trait LCDColorConst {
const WHITE: Self;
const BLACK: Self;
const CLEAR: Self;
const XOR: Self;
}

impl LCDColorConst for LCDColor {
const WHITE: Self = LCDSolidColor::kColorWhite as Self;
const BLACK: Self = LCDSolidColor::kColorBlack as Self;
const CLEAR: Self = LCDSolidColor::kColorClear as Self;
const XOR: Self = LCDSolidColor::kColorXOR as Self;
}

impl LCDColorConst for LCDSolidColor {
const WHITE: Self = LCDSolidColor::kColorWhite as Self;
const BLACK: Self = LCDSolidColor::kColorBlack as Self;
const CLEAR: Self = LCDSolidColor::kColorClear as Self;
const XOR: Self = LCDSolidColor::kColorXOR as Self;
}


#[const_trait]
// TODO: LCDColorIs should be const_trait
pub trait LCDColorIs {
fn is_solid(&self) -> bool;
fn is_pattern(&self) -> bool;
}

impl const LCDColorIs for LCDColor {
impl LCDColorIs for LCDColor {
fn is_solid(&self) -> bool {
let color = *self as usize;
color >= LCDSolidColor::kColorBlack as _ && color <= LCDSolidColor::kColorXOR as _
Expand All @@ -104,12 +128,12 @@ impl const LCDColorIs for LCDColor {
}


#[const_trait]
// TODO: IntoLCDColor should be const_trait
pub trait IntoLCDColor {
fn into_color(self) -> LCDColor;
}

impl const IntoLCDColor for LCDSolidColor {
impl IntoLCDColor for LCDSolidColor {
fn into_color(self) -> LCDColor { self as LCDColor }
}

Expand All @@ -119,13 +143,13 @@ impl<'t> IntoLCDColor for &'t LCDPattern where LCDColor: 't {
}


#[const_trait]
// TODO: LCDColorFmt should be const_trait
pub trait LCDColorFmt<'t> {
type Display: 't + core::fmt::Debug + core::fmt::Display;
fn display(&'t self) -> Self::Display;
}

impl<'t> const LCDColorFmt<'t> for LCDSolidColor {
impl<'t> LCDColorFmt<'t> for LCDSolidColor {
type Display = LCDColorDisplay<'t, Self>;
fn display(&self) -> LCDColorDisplay<'_, Self> { LCDColorDisplay(self) }
}
Expand Down
2 changes: 1 addition & 1 deletion api/ctrl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playdate-controls"
version = "0.3.5"
version = "0.3.6"
readme = "README.md"
description = "High-level controls API built on-top of Playdate API"
keywords = ["playdate", "sdk", "api", "gamedev"]
Expand Down
2 changes: 1 addition & 1 deletion api/ctrl/src/buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub trait PDButtonsExt: Sized + BitAnd<Self> {
}


impl const PDButtonsExt for PDButtons {
impl PDButtonsExt for PDButtons {
#![allow(non_snake_case)]

#[inline(always)]
Expand Down
4 changes: 2 additions & 2 deletions api/ctrl/src/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ impl Peripherals<api::Default> {
}


#[const_trait]
// TODO: SystemExt should be const_trait
pub trait SystemExt<Api: api::Api + Copy> {
fn peripherals(&self) -> Peripherals<Api>;
fn accelerometer(&self) -> Accelerometer<Api>;
fn buttons(&self) -> Buttons<Api>;
fn crank(&self) -> Crank<Api>;
}

impl<Api: system::api::Api + api::Api + Copy> const SystemExt<Api> for system::System<Api> {
impl<Api: system::api::Api + api::Api + Copy> SystemExt<Api> for system::System<Api> {
fn peripherals(&self) -> Peripherals<Api> { Peripherals::new_with(self.inner()) }
fn accelerometer(&self) -> Accelerometer<Api> { Accelerometer::new_with(self.inner()) }
fn buttons(&self) -> Buttons<Api> { Buttons::new_with(self.inner()) }
Expand Down
2 changes: 1 addition & 1 deletion api/fs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playdate-fs"
version = "0.2.8"
version = "0.2.9"
readme = "README.md"
description = "High-level file-system API built on-top of Playdate API"
keywords = ["playdate", "sdk", "api", "gamedev"]
Expand Down
1 change: 0 additions & 1 deletion api/fs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg_attr(not(test), no_std)]
#![feature(error_in_core)]
#![feature(const_trait_impl)]

#[macro_use]
Expand Down
4 changes: 2 additions & 2 deletions api/fs/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::error::ApiError;


/// Extension for [`sys::ffi::FileOptions`] make it looks like [`std::fs::OpenOptions`].
#[const_trait]
// TODO: FileOptionsExt should be const_trait
pub trait FileOptionsExt: Into<FileOptions> {
/// Creates new empty file options.
fn new() -> Self;
Expand Down Expand Up @@ -55,7 +55,7 @@ impl OpenOptions for FileOptions {
}


impl const FileOptionsExt for FileOptions {
impl FileOptionsExt for FileOptions {
fn new() -> Self { FileOptions(0) }

/// Read access to Game’s package (bundle) directory.
Expand Down
2 changes: 1 addition & 1 deletion api/gfx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playdate-graphics"
version = "0.4.0"
version = "0.4.1"
readme = "README.md"
description = "High-level graphics API built on-top of Playdate API"
keywords = ["playdate", "sdk", "api", "gamedev"]
Expand Down
1 change: 0 additions & 1 deletion api/gfx/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Playdate graphics API
#![cfg_attr(not(test), no_std)]
#![feature(error_in_core)]

extern crate sys;
extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion api/lua/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playdate-lua"
version = "0.1.1"
version = "0.1.2"
readme = "README.md"
description = "High-level Lua API built on-top of Playdate API"
keywords = ["playdate", "sdk", "api", "gamedev"]
Expand Down
1 change: 0 additions & 1 deletion api/lua/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg_attr(not(test), no_std)]
#![feature(error_in_core)]

// #[macro_use]
extern crate sys;
Expand Down
2 changes: 1 addition & 1 deletion api/menu/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playdate-menu"
version = "0.2.4"
version = "0.2.5"
readme = "README.md"
description = "High-level system menu API built on-top of Playdate API"
keywords = ["playdate", "sdk", "api", "gamedev"]
Expand Down
1 change: 0 additions & 1 deletion api/menu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg_attr(not(test), no_std)]
#![feature(error_in_core)]

#[macro_use]
extern crate sys;
Expand Down
2 changes: 1 addition & 1 deletion api/scoreboards/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playdate-scoreboards"
version = "0.1.2"
version = "0.1.3"
readme = "README.md"
description = "High-level Scoreboards API built on-top of Playdate API"
keywords = ["playdate", "sdk", "api", "gamedev"]
Expand Down
1 change: 0 additions & 1 deletion api/scoreboards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! [Official documentation](https://help.play.date/catalog-developer/scoreboard-api/#c-api-reference).
#![cfg_attr(not(test), no_std)]
#![feature(error_in_core)]

#[macro_use]
extern crate sys;
Expand Down
2 changes: 1 addition & 1 deletion api/sound/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playdate-sound"
version = "0.4.1"
version = "0.4.2"
readme = "README.md"
description = "High-level sound API built on-top of Playdate API"
keywords = ["playdate", "sdk", "api", "gamedev"]
Expand Down
1 change: 0 additions & 1 deletion api/sound/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg_attr(not(test), no_std)]
#![feature(error_in_core)]
#![feature(const_trait_impl)]

use core::ffi::c_int;
Expand Down
2 changes: 1 addition & 1 deletion api/sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _I've experimented enough with wrapping the entire API with results at every ste

## Prerequisites

<abbr title="Minimal Nightly Rust Version">MNRV</abbr> is [`1.81.0` from 2024-06-29][rust-toolchain.toml]
<abbr title="Minimal Nightly Rust Version">MNRV</abbr> is [`1.81.0` from 2024-06-30][rust-toolchain.toml]

1. Rust __nightly__ toolchain (rustup is optional)
1. [Playdate SDK][sdk]
Expand Down
1 change: 0 additions & 1 deletion api/sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#![cfg_attr(feature = "allocator", feature(allocator_api))]
#![cfg_attr(feature = "allocator", feature(alloc_layout_extra))]
// error
#![feature(error_in_core)]
#![cfg_attr(feature = "try-trait-v2", feature(try_trait_v2))]
// experimental features
#![cfg_attr(feature = "bindings-derive-constparamty",
Expand Down
Loading

0 comments on commit 0a71b9f

Please sign in to comment.