mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Add an owned slice type which cbindgen can understand.
Passing these by value won't be ok of course, but that's fine. I plan to combine this with https://github.com/eqrion/cbindgen/pull/333 to actually be able to share representation for ~all the things, this is just the first bit. Box<T>, Atom and Arc<T> will be much easier since cbindgen can understand them without issues. It's boxed slices the only ones I should need something like this. I could avoid it if I rely on Rust's internal representation, which we can per [1], but then I need to teach cbindgen all about slices, which is generally hard, I think. [1]: https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/pointers.md Differential Revision: https://phabricator.services.mozilla.com/D29768
This commit is contained in:
parent
4b761848a0
commit
330bccd659
6 changed files with 252 additions and 1 deletions
|
@ -288,6 +288,50 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> ToAnimatedValue for Box<[T]>
|
||||
where
|
||||
T: ToAnimatedValue,
|
||||
{
|
||||
type AnimatedValue = Box<[<T as ToAnimatedValue>::AnimatedValue]>;
|
||||
|
||||
#[inline]
|
||||
fn to_animated_value(self) -> Self::AnimatedValue {
|
||||
self
|
||||
.into_vec()
|
||||
.into_iter()
|
||||
.map(T::to_animated_value)
|
||||
.collect::<Vec<_>>()
|
||||
.into_boxed_slice()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
animated
|
||||
.into_vec()
|
||||
.into_iter()
|
||||
.map(T::from_animated_value)
|
||||
.collect::<Vec<_>>()
|
||||
.into_boxed_slice()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ToAnimatedValue for crate::OwnedSlice<T>
|
||||
where
|
||||
T: ToAnimatedValue,
|
||||
{
|
||||
type AnimatedValue = crate::OwnedSlice<<T as ToAnimatedValue>::AnimatedValue>;
|
||||
|
||||
#[inline]
|
||||
fn to_animated_value(self) -> Self::AnimatedValue {
|
||||
self.into_box().to_animated_value().into()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
Box::from_animated_value(animated.into_box()).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ToAnimatedValue for SmallVec<[T; 1]>
|
||||
where
|
||||
T: ToAnimatedValue,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue