opencv_binding_generator/
map_borrowed.rs1use std::borrow::{Borrow, Cow};
2
3pub trait CowMapBorrowedExt<'c, 'b, IN, OUT>
4where
5 IN: ToOwned + ?Sized + 'b,
6 OUT: ToOwned + ?Sized + 'b,
7{
8 fn map_borrowed<F>(self, f: F) -> Cow<'c, OUT>
9 where
10 F: for<'f> FnOnce(&'f IN) -> Cow<'f, OUT>;
11}
12
13impl<'c, 'b, IN, OUT> CowMapBorrowedExt<'c, 'b, IN, OUT> for Cow<'c, IN>
14where
15 IN: ToOwned + ?Sized + 'b,
16 OUT: ToOwned + ?Sized + 'b,
17{
18 #[inline(always)]
19 fn map_borrowed<F>(self, f: F) -> Cow<'c, OUT>
20 where
21 F: for<'f> FnOnce(&'f IN) -> Cow<'f, OUT>,
22 {
23 match self {
24 Cow::Borrowed(v) => f(v),
25 Cow::Owned(v) => Cow::Owned(f(v.borrow()).into_owned()),
26 }
27 }
28}