Struct screeps::pathfinder::LocalCostMatrix
source · [−]pub struct LocalCostMatrix { /* private fields */ }
Implementations
sourceimpl LocalCostMatrix
impl LocalCostMatrix
pub fn new() -> Self
pub fn set(&mut self, x: u8, y: u8, val: u8)
pub fn get(&self, x: u8, y: u8) -> u8
sourcepub fn upload(&self) -> CostMatrix<'static>
pub fn upload(&self) -> CostMatrix<'static>
Copies all data into an JavaScript CostMatrix for use.
This is slower than as_uploaded
, but much safer.
sourcepub unsafe fn as_uploaded<'a>(&'a self) -> CostMatrix<'a>
pub unsafe fn as_uploaded<'a>(&'a self) -> CostMatrix<'a>
Temporarily exposes the bits of this matrix as a cost matrix.
Unsafety
There are two main invariants you must uphold after using this function:
-
The
CostMatrix
can only be used in JS code as long as thisLocalCostMatrix
is alive. Doing otherwise will result in undefined behavior, mainly JS being allowed to read/ manipulate uninitialized rust memory or rust memory that’s been repurposed. -
The
set
method of the cost matrix must not be used - it must be read only. This takes &self, but technically allows mutation of the inner Vec via JavaScript access. You should not use this method, or you will invoke Rust undefined behavior.
The CostMatrix returned will reference the internal data of this
LocalCostMatrix
.
Trait Implementations
sourceimpl Clone for LocalCostMatrix
impl Clone for LocalCostMatrix
sourcefn clone(&self) -> LocalCostMatrix
fn clone(&self) -> LocalCostMatrix
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a> CostMatrixSet for LocalCostMatrix
impl<'a> CostMatrixSet for LocalCostMatrix
fn set_multi<D, B, P, V>(&mut self, data: D)where
D: IntoIterator<Item = B>,
B: Borrow<(P, V)>,
P: HasLocalPosition,
V: Borrow<u8>,
fn set<P, V>(&mut self, position: P, cost: V)where
P: HasLocalPosition,
V: Borrow<u8>,
sourceimpl Debug for LocalCostMatrix
impl Debug for LocalCostMatrix
sourceimpl Default for LocalCostMatrix
impl Default for LocalCostMatrix
sourceimpl<'de> Deserialize<'de> for LocalCostMatrix
impl<'de> Deserialize<'de> for LocalCostMatrix
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Serialize for LocalCostMatrix
impl Serialize for LocalCostMatrix
Auto Trait Implementations
impl RefUnwindSafe for LocalCostMatrix
impl Send for LocalCostMatrix
impl Sync for LocalCostMatrix
impl Unpin for LocalCostMatrix
impl UnwindSafe for LocalCostMatrix
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T, U> IntoExpectedType<U> for Twhere
U: FromExpectedType<T>,
impl<T, U> IntoExpectedType<U> for Twhere
U: FromExpectedType<T>,
sourcefn into_expected_type(self) -> Result<U, ConversionError>
fn into_expected_type(self) -> Result<U, ConversionError>
Casts this value as the target type, making the assumption that the types are correct. Read more