Skip to content

Commit

Permalink
fix const_trait usage, CI fixes,
Browse files Browse the repository at this point in the history
fmt, because some nightly rustfmt fixes
  • Loading branch information
boozook committed Jul 13, 2024
1 parent 549fc34 commit 6529a84
Show file tree
Hide file tree
Showing 31 changed files with 157 additions and 158 deletions.
30 changes: 4 additions & 26 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -475,31 +475,11 @@ 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
if: github.event_name == 'pull_request'
name: Clippy + fmt suggestions
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
defaults:
run:
shell: bash
Expand All @@ -521,7 +501,6 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
# fetch-depth: 2

- name: Install Clippy
run: rustup component add clippy
Expand Down Expand Up @@ -557,7 +536,6 @@ jobs:
-p=playdate-tool
--bins --examples --all-targets
-- -Aclippy::cargo
|| (echo "::error::Rust format error." && exit 1)
# needed after clippy fix
- name: fmt
Expand All @@ -572,6 +550,6 @@ jobs:
with:
filter_mode: diff_context
fail_on_error: false
tool_name: Clippy
tool_name: Clippy & fmt
cleanup: false

26 changes: 13 additions & 13 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
Loading

0 comments on commit 6529a84

Please sign in to comment.