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 13, 2019
1 parent 62d2574 commit 075794c
Show file tree
Hide file tree
Showing 4 changed files with 11 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 @@ -167,7 +167,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 @@ -232,7 +232,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
4 changes: 1 addition & 3 deletions victor/src/layout/flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ fn layout_block_level_children<'a>(
&mut placement_state.current_margin,
fragment.block_margins_collapsed_with_children.end,
);
if placement_state
.next_in_flow_margin_collapses_with_parent_start_margin
.take()
if take(&mut placement_state.next_in_flow_margin_collapses_with_parent_start_margin)
{
debug_assert_eq!(current_margin.solve(), Length::zero());
debug_assert_eq!(placement_state.start_margin.solve(), Length::zero());
Expand Down
12 changes: 4 additions & 8 deletions victor/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,11 @@ fn relative_adjustement(
}
}

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

impl<T> Take for T
// 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,
{
fn take(&mut self) -> Self {
std::mem::replace(self, Default::default())
}
std::mem::replace(x, Default::default())
}

0 comments on commit 075794c

Please sign in to comment.