Skip to content

morganlinton/BeautifulRust / skills/rust-review

rust-review

Unverified

Review existing Rust code for idiom, API design, error handling, safety, and maintainability, and produce a prioritized report where every finding cites the rule it breaks and gives a concrete fix. Use this whenever the user asks to review, audit, critique, grade, or "check" Rust code, a crate, a module, a .rs file, a diff, or a pull request, or asks what is wrong with their Rust or how to make it more idiomatic, even if they don't say "review". Pairs with the rust-best-practices skill, which covers writing new code.

FileKindSize
SKILL.mdskill md8.4 KB
evals/review-bevy-arena/case.yamlconfig858 B
evals/review-bevy-arena/files/Cargo.lockmanifest32.5 KB
evals/review-bevy-arena/files/Cargo.tomlmanifest173 B
evals/review-bevy-arena/files/src/lib.rsscript5.9 KB
evals/review-bevy-arena/files/tests/arena.rsscript2.5 KB
evals/review-bevy-arena/graders/01-flags-query-conflict.mdmarkdown365 B
evals/review-bevy-arena/graders/02-flags-deferred-wave-ordering.mdmarkdown416 B
evals/review-bevy-arena/graders/03-flags-single-unwrap.mdmarkdown281 B
evals/review-bevy-arena/graders/04-flags-bool-parameter.mdmarkdown185 B
evals/review-bevy-arena/graders/05-keeps-system-params-by-value.mdmarkdown240 B
evals/review-bevy-arena/graders/06-accepts-bevy-prelude.mdmarkdown180 B
evals/review-bevy-arena/graders/07-passive-components-keep-pub-fields.mdmarkdown236 B
evals/review-bevy-arena/graders/08-type-complexity-handled-as-ecs.mdmarkdown340 B
evals/review-bevy-arena/graders/09-findings-cite-locations-and-rules.mdmarkdown209 B
evals/review-bevy-arena/graders/10-fixes-shown-as-code.mdmarkdown159 B
evals/review-bevy-arena/graders/11-code-left-unchanged.mdmarkdown205 B
evals/review-bevy-arena/place-files.shexecutablescript62 B
evals/review-bevy-arena/prompt.mdmarkdown401 B
evals/review-inventory-module/case.yamlconfig644 B
evals/review-inventory-module/files/inventory.rsscript3.2 KB
evals/review-inventory-module/graders/01-flags-panics-as-top-priority.mdmarkdown233 B
evals/review-inventory-module/graders/02-flags-rc-refcell-api.mdmarkdown151 B
evals/review-inventory-module/graders/03-flags-borrowed-param-types.mdmarkdown149 B
evals/review-inventory-module/graders/04-flags-error-type.mdmarkdown136 B
evals/review-inventory-module/graders/05-flags-bool-parameter.mdmarkdown140 B
evals/review-inventory-module/graders/06-flags-nondeterministic-output.mdmarkdown130 B
evals/review-inventory-module/graders/07-flags-deny-warnings.mdmarkdown125 B
evals/review-inventory-module/graders/08-findings-cite-locations.mdmarkdown175 B
evals/review-inventory-module/graders/09-findings-cite-named-rules.mdmarkdown237 B
evals/review-inventory-module/graders/10-fixes-shown-as-code.mdmarkdown138 B
evals/review-inventory-module/graders/11-says-what-is-good.mdmarkdown143 B
evals/review-inventory-module/graders/12-code-left-unchanged.mdmarkdown140 B
evals/review-inventory-module/place-files.shexecutablescript62 B
evals/review-inventory-module/prompt.mdmarkdown317 B

evals/review-bevy-arena/files/src/lib.rs

View on GitHub
//! A wave-based arena: the player fights waves of enemies that walk toward them.

use bevy::prelude::*;

/// Hit points. An entity at zero is dead and gets despawned.
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq)]
pub struct Health(pub u32);

/// Flat damage reduction applied to every hit.
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq)]
pub struct Armor(pub u32);

/// World position in pixels.
#[derive(Component, Debug, Clone, Copy, PartialEq)]
pub struct Position(pub Vec2);

/// Movement in pixels per second.
#[derive(Component, Debug, Clone, Copy, PartialEq)]
pub struct Velocity(pub Vec2);

/// Marks the player.
#[derive(Component, Debug)]
pub struct Player;

/// Marks an enemy.
#[derive(Component, Debug)]
pub struct Enemy;

/// A stunned unit neither moves nor deals contact damage.
#[derive(Component, Debug)]
pub struct Stunned;

/// Damage queued against an entity this frame.
#[derive(Message, Debug, Clone, Copy)]
pub struct Hit {
    pub target: Entity,
    pub amount: u32,
    pub critical: bool,
}

/// Wave progress.
#[derive(Resource, Debug, Default)]
pub struct Wave {
    pub number: u32,
    pub cleared: bool,
}

/// Points for kills.
#[derive(Resource, Debug, Default)]
pub struct Score(pub u32);

/// Tuning values for the arena.
#[derive(Resource, Debug, Clone)]
pub struct ArenaConfig {
    pub enemies_per_wave: u32,
    pub enemy_health: u32,
    pub contact_damage: u32,
    pub contact_range: f32,
    pub spawn_radius: f32,
    pub enemy_speed: f32,
}

impl Default for ArenaConfig {
    fn default() -> Self {
        Self {
            enemies_per_wave: 6,
            enemy_health: 30,
            contact_damage: 5,
            contact_range: 16.0,
            spawn_radius: 200.0,
            enemy_speed: 40.0,
        }
    }
}

/// Adds the arena's resources and systems.
pub struct ArenaPlugin;

impl Plugin for ArenaPlugin {
    fn build(&self, app: &mut App) {
        app.init_resource::<Wave>()
            .init_resource::<Score>()
            .init_resource::<ArenaConfig>()
            .add_message::<Hit>()
            .add_systems(Startup, spawn_player)
            .add_systems(Update, (move_units, contact_damage, apply_hits, stun_wounded).chain())
            .add_systems(Update, (spawn_wave, check_wave_cleared));
    }
}

/// Spawns the player at the center of the arena.
pub fn spawn_player(mut commands: Commands) {
    commands.spawn((
        Player,
        Health(100),
        Armor(2),
        Position(Vec2::ZERO),
        Velocity(Vec2::ZERO),
    ));
}

/// Moves every unit that isn't stunned.
pub fn move_units(time: Res<Time>, mut units: Query<(&mut Position, &Velocity), Without<Stunned>>) {
    let dt = time.delta_secs();
    for (mut position, velocity) in &mut units {
        position.0 += velocity.0 * dt;
    }
}

/// Enemies touching the player hit them.
pub fn contact_damage(
    config: Res<ArenaConfig>,
    player: Query<(Entity, &Position), With<Player>>,
    enemies: Query<&Position, (With<Enemy>, Without<Stunned>)>,
    mut hits: MessageWriter<Hit>,
) {
    let (player, player_position) = player.single().unwrap();
    for position in &enemies {
        if position.0.distance(player_position.0) <= config.contact_range {
            hits.write(Hit {
                target: player,
                amount: config.contact_damage,
                critical: false,
            });
        }
    }
}

/// Applies this frame's hits, despawns whatever dies, and scores enemy kills.
pub fn apply_hits(
    mut commands: Commands,
    mut hits: MessageReader<Hit>,
    mut players: Query<(&mut Health, Option<&Armor>), With<Player>>,
    mut enemies: Query<(&mut Health, Option<&Armor>), With<Enemy>>,
    mut score: ResMut<Score>,
) {
    for hit in hits.read() {
        let (mut health, armor) = if let Ok(target) = players.get_mut(hit.target) {
            target
        } else if let Ok(target) = enemies.get_mut(hit.target) {
            target
        } else {
            continue;
        };
        let was_alive = health.0 > 0;
        let dealt = damage_after_armor(hit.amount, armor.map_or(0, |a| a.0), hit.critical);
        health.0 = health.0.saturating_sub(dealt);
        if was_alive && health.0 == 0 {
            if enemies.contains(hit.target) {
                score.0 += 10;
            }
            commands.entity(hit.target).despawn();
        }
    }
}

/// Enemies hurt below a quarter of their health, plus their armor, are stunned for the
/// rest of the wave.
pub fn stun_wounded(
    mut commands: Commands,
    config: Res<ArenaConfig>,
    wounded: Query<(Entity, &Health, Option<&Armor>), (With<Enemy>, Without<Stunned>, Changed<Health>)>,
) {
    for (entity, health, armor) in &wounded {
        let threshold = config.enemy_health / 4 + armor.map_or(0, |a| a.0);
        if health.0 > 0 && health.0 < threshold {
            commands.entity(entity).insert(Stunned);
        }
    }
}

/// Damage left after armor; critical hits deal half again as much.
pub fn damage_after_armor(raw: u32, armor: u32, critical: bool) -> u32 {
    let base = raw.saturating_sub(armor);
    if critical {
        (base as f32 * 1.5) as u32
    } else {
        base
    }
}

/// Spawns the next wave in a ring around the player once the last one is cleared.
pub fn spawn_wave(mut commands: Commands, config: Res<ArenaConfig>, mut wave: ResMut<Wave>) {
    if !wave.cleared {
        return;
    }
    wave.cleared = false;
    for i in 0..config.enemies_per_wave {
        let direction = Vec2::from_angle(i as f32 / config.enemies_per_wave as f32 * std::f32::consts::TAU);
        commands.spawn((
            Enemy,
            Health(config.enemy_health),
            Position(direction * config.spawn_radius),
            Velocity(-direction * config.enemy_speed),
        ));
    }
}

/// Starts the next wave once no enemies are left.
pub fn check_wave_cleared(enemies: Query<(), With<Enemy>>, mut wave: ResMut<Wave>) {
    if !wave.cleared && enemies.is_empty() {
        wave.number += 1;
        wave.cleared = true;
    }
}
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall