Skip to content

Commit

Permalink
Replace the Take trait with a function like std::mem::take
Browse files Browse the repository at this point in the history
To be replaced when the std one is stable
rust-lang/rust#61129
  • Loading branch information
SimonSapin committed Jun 8, 2019
1 parent fd9b2d4 commit 6705b16
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
8 changes: 4 additions & 4 deletions victor/src/layout/flow/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl<'a> BlockContainerBuilder<'a> {
// The fragmented boxes before the block level element
// are obviously not the last fragment.
last_fragment: false,
children: ongoing.children.take(),
children: take(&mut ongoing.children),
};
ongoing.first_fragment = false;
fragmented
Expand Down Expand Up @@ -462,9 +462,9 @@ impl<'a> BlockContainerBuilder<'a> {
self.block_level_boxes
.push(IntermediateBlockLevelBox::SameFormattingContextBlock {
style: anonymous_style.clone(),
contents: IntermediateBlockContainer::InlineFormattingContext(
self.ongoing_inline_formatting_context.take(),
),
contents: IntermediateBlockContainer::InlineFormattingContext(take(
&mut self.ongoing_inline_formatting_context,
)),
});
}

Expand Down
4 changes: 2 additions & 2 deletions victor/src/layout/flow/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl LinesBoxes {
};
self.next_line_block_position += size.block;
self.boxes.push(Fragment::Anonymous(AnonymousFragment {
children: top_nesting_level.fragments_so_far.take(),
children: take(&mut top_nesting_level.fragments_so_far),
rect: Rect { start_corner, size },
mode: containing_block.mode,
}))
Expand Down Expand Up @@ -231,7 +231,7 @@ impl<'box_tree> PartialInlineBoxFragment<'box_tree> {
) {
let mut fragment = BoxFragment {
style: self.style.clone(),
children: nesting_level.fragments_so_far.take(),
children: take(&mut nesting_level.fragments_so_far),
content_rect: Rect {
size: Vec2 {
inline: *inline_position - self.start_corner.inline,
Expand Down
15 changes: 4 additions & 11 deletions victor/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,8 @@ fn relative_adjustement(
}
}

trait Take {
fn take(&mut self) -> Self;
}

impl<T> Take for T
where
T: Default,
{
fn take(&mut self) -> Self {
std::mem::replace(self, Default::default())
}
// FIXME: use std::mem::take when it’s stable
// https://github.com/rust-lang/rust/issues/61129
fn take<T>(x: &mut T) -> T where T: Default {
std::mem::replace(x, Default::default())
}

0 comments on commit 6705b16

Please sign in to comment.