Skip to content

Commit

Permalink
Merge pull request #39 from MrGVSV/clippy
Browse files Browse the repository at this point in the history
Add basic CI workflow
  • Loading branch information
MrGVSV authored May 4, 2023
2 parents b5e643b + a49c385 commit e19c6a9
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 25 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# partially adopted from https://github.com/Leafwing-Studios/Emergence/blob/main/.github/workflows/ci.yml

name: CI

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]

env:
CARGO_TERM_COLOR: always
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

jobs:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: 🦀 Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: 📦 Cache cargo
uses: Leafwing-Studios/cargo-cache@v1
- name: 📥 Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev
- name: 🧪 Run rustfmt
run: cargo fmt --check
clippy-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: 🦀 Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: 📦 Cache cargo
uses: Leafwing-Studios/cargo-cache@v1
- name: 📥 Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev
- name: 🧪 Run clippy
run: cargo clippy --workspace --examples --all-targets --all-features -- -D warnings
2 changes: 0 additions & 2 deletions bevy_proto_backend/src/load/loader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(not(test))]

use std::cmp::Reverse;
use std::marker::PhantomData;
use std::sync::Arc;
Expand Down
4 changes: 2 additions & 2 deletions bevy_proto_backend/src/path/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<'a> ProtoPathDeserializer<'a> {
}
}

impl<'a, 'ctx, 'load_ctx, 'de> DeserializeSeed<'de> for ProtoPathDeserializer<'a> {
impl<'a, 'de> DeserializeSeed<'de> for ProtoPathDeserializer<'a> {
type Value = ProtoPath;

fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
Expand All @@ -27,7 +27,7 @@ impl<'a, 'ctx, 'load_ctx, 'de> DeserializeSeed<'de> for ProtoPathDeserializer<'a
context: &'a dyn ProtoPathContext,
}

impl<'a, 'ctx, 'load_ctx, 'de> Visitor<'de> for PathVisitor<'a> {
impl<'a, 'de> Visitor<'de> for PathVisitor<'a> {
type Value = ProtoPath;

fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion bevy_proto_backend/src/proto/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl<T: Prototypical> ProtoCommandData<T> {
let handle = prototypes.get_handle(*handle_id);
let proto = prototypes.get(&handle).unwrap();

if proto.requires_entity() && !context.entity().is_some() {
if proto.requires_entity() && context.entity().is_none() {
panic!(
"could not apply command for prototype {:?}: requires entity",
proto.id()
Expand Down
4 changes: 2 additions & 2 deletions bevy_proto_backend/src/proto/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub enum ProtoError {
#[error("attempted to register prototype with ID {id:?} (`{path:?}`), but one already exists with this ID (`{existing:?}`)")]
AlreadyExists {
id: String,
path: AssetPath<'static>,
existing: AssetPath<'static>,
path: Box<AssetPath<'static>>,
existing: Box<AssetPath<'static>>,
},
/// Indicates that an operation that requires an entity was attempted on a prototype that doesn't require one.
///
Expand Down
16 changes: 8 additions & 8 deletions bevy_proto_backend/src/registration/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ impl<T: Prototypical> ProtoRegistry<T> {
/// Removes a prototype from the registry.
///
/// Returns the ID of the prototype if it was registered.
pub(super) fn unregister<'w>(
pub(super) fn unregister(
&mut self,
handle: &Handle<T>,
params: &mut RegistryParams<'w, T>,
params: &mut RegistryParams<T>,
) -> Option<T::Id> {
let id = self.unregister_internal(handle, params)?;

Expand Down Expand Up @@ -156,8 +156,8 @@ impl<T: Prototypical> ProtoRegistry<T> {
if self.ids.contains_key(&handle.id()) {
return Err(ProtoError::AlreadyExists {
id: prototype.id().to_string(),
path: prototype.path().into(),
existing: prototype.path().into(),
path: Box::new(prototype.path().into()),
existing: Box::new(prototype.path().into()),
});
}

Expand All @@ -169,8 +169,8 @@ impl<T: Prototypical> ProtoRegistry<T> {
let exiting_prototype = params.get_prototype(&handle)?;
return Err(ProtoError::AlreadyExists {
id: prototype.id().to_string(),
path: prototype.path().into(),
existing: exiting_prototype.path().into(),
path: Box::new(prototype.path().into()),
existing: Box::new(exiting_prototype.path().into()),
});
}
}
Expand All @@ -189,10 +189,10 @@ impl<T: Prototypical> ProtoRegistry<T> {
Ok(prototype)
}

fn unregister_internal<'w>(
fn unregister_internal(
&mut self,
handle: &Handle<T>,
params: &mut RegistryParams<'w, T>,
params: &mut RegistryParams<T>,
) -> Option<T::Id> {
let handle_id = handle.id();

Expand Down
18 changes: 10 additions & 8 deletions bevy_proto_backend/src/registration/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ pub(crate) fn on_proto_asset_event<T: Prototypical>(
) {
for event in events.iter() {
match event {
AssetEvent::Created { handle } => match manager.register(handle) {
Err(err) => error!("could not register prototype: {}", err),
_ => {}
},
AssetEvent::Modified { handle } => match manager.reload(handle) {
Err(err) => error!("could not reload modified prototype: {}", err),
_ => {}
},
AssetEvent::Created { handle } => {
if let Err(err) = manager.register(handle) {
error!("could not register prototype: {}", err);
}
}
AssetEvent::Modified { handle } => {
if let Err(err) = manager.reload(handle) {
error!("could not reload modified prototype: {}", err);
}
}
AssetEvent::Removed { handle } => {
manager.unregister(handle);
}
Expand Down
4 changes: 2 additions & 2 deletions src/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ from!(
bevy::scene::DynamicSceneBundle,
DynamicSceneBundle,
|value: Input| Self {
scene: value.scene.into(),
scene: value.scene,
transform: value.transform,
global_transform: value.global_transform,
visibility: value.visibility,
Expand Down Expand Up @@ -452,7 +452,7 @@ pub struct SceneBundle {

#[cfg(feature = "bevy_scene")]
from!(bevy::scene::SceneBundle, SceneBundle, |value: Input| Self {
scene: value.scene.into(),
scene: value.scene,
transform: value.transform,
global_transform: value.global_transform,
visibility: value.visibility,
Expand Down

0 comments on commit e19c6a9

Please sign in to comment.