I have a (trait) function like this, which copies data from a 2d map (self) to another 2d map (dst).
fn copy_rect<DstMap>(&self, dst: &mut DstMap, src_rect: &Rect, dst_point: &Point)
where
DstMap: MapTrait<T>
{
// do my thing
}
Now I would like to have a version which uses a clip_rect (avoid drawing outside this rect).
Of course I can duplicate the code with an extra parameter.
But I was wondering if it is possible to change the function and add a clip_rect: Option<&Rect> parameter. With the extra requirement that it will be monomorphized. Performance is quite important.
fn copy_rect<DstMap>(&self, dst: &mut DstMap, src_rect: &Rect, dst_point: &Point,
clip_rect: Option<&Rect>)
where
DstMap: MapTrait<T>
{
if let Some(clip) = clip_rect
{
// do some extra clipping
}
// do my thing
}
When I call the function like this:
map.copy_rect(dst, src_rect, dst_point, None);
I guess the compiler is smart enough?
Anyway: what would be the smartest / most performant way to do this without creating an extra function?