Skip to content

Commit

Permalink
Merge branch 'main' into flat_bindgen_complete
Browse files Browse the repository at this point in the history
  • Loading branch information
shanemadden committed Jun 25, 2024
2 parents 1ab5905 + bb74f6d commit 16f0c6b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Unreleased
- Add function `Direction::iter` which returns an iterator over all the `Direction` enum values
- Add function `RoomXY::neighbors` which returns an iterator over all the valid neighbors of
a given `RoomXY` position
- Add static function `LocalCostMatrix::new_with_value` which returns a `LocalCostMatrix` with
every position set to a given `u8` value

0.21.0 (2024-05-14)
===================
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@

// #![warn(clippy::missing_const_for_fn)]

// temporary workaround for https://github.com/rust-lang/rust-clippy/issues/12377
// fix not being in current stable rust 1.78; should be fixed in 1.79
#![allow(clippy::empty_docs)]

pub mod console;
pub mod constants;
pub mod enums;
Expand Down
29 changes: 28 additions & 1 deletion src/local/cost_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,37 @@ impl Default for LocalCostMatrix {
}

impl LocalCostMatrix {
/// Create a `LocalCostMatrix` with a default value of 0 for all positions.
///
/// # Example
///
/// ```rust
/// use screeps::local::{LocalCostMatrix, RoomXY};
///
/// let lcm = LocalCostMatrix::new();
/// let pos = unsafe { RoomXY::unchecked_new(10, 10) };
/// assert_eq!(lcm.get(pos), 0);
/// ```
#[inline]
pub const fn new() -> Self {
LocalCostMatrix::new_with_value(0)
}

/// Create a `LocalCostMatrix` with a default value for all positions.
///
/// # Example
///
/// ```rust
/// use screeps::local::{LocalCostMatrix, RoomXY};
///
/// let lcm = LocalCostMatrix::new_with_value(u8::MAX);
/// let pos = unsafe { RoomXY::unchecked_new(10, 10) };
/// assert_eq!(lcm.get(pos), u8::MAX);
/// ```
#[inline]
pub const fn new_with_value(value: u8) -> Self {
LocalCostMatrix {
bits: [0; ROOM_AREA],
bits: [value; ROOM_AREA],
}
}

Expand Down

0 comments on commit 16f0c6b

Please sign in to comment.