logo
pub trait TryMapCoordsInplace<T, E> {
    fn try_map_coords_inplace(
        &mut self,
        func: impl Fn(&(T, T)) -> Result<(T, T), E>
    ) -> Result<(), E>
    where
        T: CoordNum
; }
Expand description

Map a fallible function over all the coordinates in a geometry, returning a Result

Required Methods

Map a fallible function over all the coordinates in a geometry, in place, returning a Result.

Upon encountering an Err from the function, try_map_coords_inplace immediately returns and the geometry is potentially left in a partially mapped state.

Examples
use geo::algorithm::map_coords::TryMapCoordsInplace;

let mut p1 = geo::point!{x: 10u32, y: 20u32};

p1.try_map_coords_inplace(|&(x, y)| -> Result<_, &str> {
    Ok((
        x.checked_add(1000).ok_or("Overflow")?,
        y.checked_mul(2).ok_or("Overflow")?,
    ))
})?;

assert_eq!(
    p1,
    geo::point!{x: 1010u32, y: 40u32},
);

Implementors