Fix clippy::trivially-copy-pass-by-ref
This commit is contained in:
parent
34f07b6027
commit
6c386e90a1
6 changed files with 48 additions and 55 deletions
|
|
@ -1,2 +1,2 @@
|
||||||
[alias]
|
[alias]
|
||||||
lint = "clippy --workspace --no-deps -- -D warnings -D clippy::semicolon_if_nothing_returned"
|
lint = "clippy --workspace --no-deps -- -D warnings -D clippy::semicolon_if_nothing_returned -D clippy::trivially-copy-pass-by-ref"
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ pub enum Kind {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Kind {
|
impl Kind {
|
||||||
fn next(&self) -> Kind {
|
fn next(self) -> Kind {
|
||||||
match self {
|
match self {
|
||||||
Kind::Single => Kind::Double,
|
Kind::Single => Kind::Double,
|
||||||
Kind::Double => Kind::Triple,
|
Kind::Double => Kind::Triple,
|
||||||
|
|
|
||||||
|
|
@ -61,11 +61,8 @@ impl Application for Example {
|
||||||
fn update(&mut self, message: Message) -> Command<Message> {
|
fn update(&mut self, message: Message) -> Command<Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::Split(axis, pane) => {
|
Message::Split(axis, pane) => {
|
||||||
let result = self.panes.split(
|
let result =
|
||||||
axis,
|
self.panes.split(axis, pane, Pane::new(self.panes_created));
|
||||||
&pane,
|
|
||||||
Pane::new(self.panes_created),
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some((pane, _)) = result {
|
if let Some((pane, _)) = result {
|
||||||
self.focus = Some(pane);
|
self.focus = Some(pane);
|
||||||
|
|
@ -77,7 +74,7 @@ impl Application for Example {
|
||||||
if let Some(pane) = self.focus {
|
if let Some(pane) = self.focus {
|
||||||
let result = self.panes.split(
|
let result = self.panes.split(
|
||||||
axis,
|
axis,
|
||||||
&pane,
|
pane,
|
||||||
Pane::new(self.panes_created),
|
Pane::new(self.panes_created),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -90,8 +87,7 @@ impl Application for Example {
|
||||||
}
|
}
|
||||||
Message::FocusAdjacent(direction) => {
|
Message::FocusAdjacent(direction) => {
|
||||||
if let Some(pane) = self.focus {
|
if let Some(pane) = self.focus {
|
||||||
if let Some(adjacent) =
|
if let Some(adjacent) = self.panes.adjacent(pane, direction)
|
||||||
self.panes.adjacent(&pane, direction)
|
|
||||||
{
|
{
|
||||||
self.focus = Some(adjacent);
|
self.focus = Some(adjacent);
|
||||||
}
|
}
|
||||||
|
|
@ -101,37 +97,34 @@ impl Application for Example {
|
||||||
self.focus = Some(pane);
|
self.focus = Some(pane);
|
||||||
}
|
}
|
||||||
Message::Resized(pane_grid::ResizeEvent { split, ratio }) => {
|
Message::Resized(pane_grid::ResizeEvent { split, ratio }) => {
|
||||||
self.panes.resize(&split, ratio);
|
self.panes.resize(split, ratio);
|
||||||
}
|
}
|
||||||
Message::Dragged(pane_grid::DragEvent::Dropped {
|
Message::Dragged(pane_grid::DragEvent::Dropped {
|
||||||
pane,
|
pane,
|
||||||
target,
|
target,
|
||||||
}) => {
|
}) => {
|
||||||
self.panes.drop(&pane, target);
|
self.panes.drop(pane, target);
|
||||||
}
|
}
|
||||||
Message::Dragged(_) => {}
|
Message::Dragged(_) => {}
|
||||||
Message::TogglePin(pane) => {
|
Message::TogglePin(pane) => {
|
||||||
if let Some(Pane { is_pinned, .. }) = self.panes.get_mut(&pane)
|
if let Some(Pane { is_pinned, .. }) = self.panes.get_mut(pane) {
|
||||||
{
|
|
||||||
*is_pinned = !*is_pinned;
|
*is_pinned = !*is_pinned;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Maximize(pane) => self.panes.maximize(&pane),
|
Message::Maximize(pane) => self.panes.maximize(pane),
|
||||||
Message::Restore => {
|
Message::Restore => {
|
||||||
self.panes.restore();
|
self.panes.restore();
|
||||||
}
|
}
|
||||||
Message::Close(pane) => {
|
Message::Close(pane) => {
|
||||||
if let Some((_, sibling)) = self.panes.close(&pane) {
|
if let Some((_, sibling)) = self.panes.close(pane) {
|
||||||
self.focus = Some(sibling);
|
self.focus = Some(sibling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::CloseFocused => {
|
Message::CloseFocused => {
|
||||||
if let Some(pane) = self.focus {
|
if let Some(pane) = self.focus {
|
||||||
if let Some(Pane { is_pinned, .. }) = self.panes.get(&pane)
|
if let Some(Pane { is_pinned, .. }) = self.panes.get(pane) {
|
||||||
{
|
|
||||||
if !is_pinned {
|
if !is_pinned {
|
||||||
if let Some((_, sibling)) = self.panes.close(&pane)
|
if let Some((_, sibling)) = self.panes.close(pane) {
|
||||||
{
|
|
||||||
self.focus = Some(sibling);
|
self.focus = Some(sibling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -443,7 +443,7 @@ pub enum Filter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Filter {
|
impl Filter {
|
||||||
fn matches(&self, task: &Task) -> bool {
|
fn matches(self, task: &Task) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Filter::All => true,
|
Filter::All => true,
|
||||||
Filter::Active => !task.completed,
|
Filter::Active => !task.completed,
|
||||||
|
|
|
||||||
|
|
@ -95,13 +95,13 @@ impl Node {
|
||||||
splits
|
splits
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn find(&mut self, pane: &Pane) -> Option<&mut Node> {
|
pub(crate) fn find(&mut self, pane: Pane) -> Option<&mut Node> {
|
||||||
match self {
|
match self {
|
||||||
Node::Split { a, b, .. } => {
|
Node::Split { a, b, .. } => {
|
||||||
a.find(pane).or_else(move || b.find(pane))
|
a.find(pane).or_else(move || b.find(pane))
|
||||||
}
|
}
|
||||||
Node::Pane(p) => {
|
Node::Pane(p) => {
|
||||||
if p == pane {
|
if *p == pane {
|
||||||
Some(self)
|
Some(self)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
@ -139,12 +139,12 @@ impl Node {
|
||||||
f(self);
|
f(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn resize(&mut self, split: &Split, percentage: f32) -> bool {
|
pub(crate) fn resize(&mut self, split: Split, percentage: f32) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Node::Split {
|
Node::Split {
|
||||||
id, ratio, a, b, ..
|
id, ratio, a, b, ..
|
||||||
} => {
|
} => {
|
||||||
if id == split {
|
if *id == split {
|
||||||
*ratio = percentage;
|
*ratio = percentage;
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
@ -158,13 +158,13 @@ impl Node {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn remove(&mut self, pane: &Pane) -> Option<Pane> {
|
pub(crate) fn remove(&mut self, pane: Pane) -> Option<Pane> {
|
||||||
match self {
|
match self {
|
||||||
Node::Split { a, b, .. } => {
|
Node::Split { a, b, .. } => {
|
||||||
if a.pane() == Some(*pane) {
|
if a.pane() == Some(pane) {
|
||||||
*self = *b.clone();
|
*self = *b.clone();
|
||||||
Some(self.first_pane())
|
Some(self.first_pane())
|
||||||
} else if b.pane() == Some(*pane) {
|
} else if b.pane() == Some(pane) {
|
||||||
*self = *a.clone();
|
*self = *a.clone();
|
||||||
Some(self.first_pane())
|
Some(self.first_pane())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -75,14 +75,14 @@ impl<T> State<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the internal state of the given [`Pane`], if it exists.
|
/// Returns the internal state of the given [`Pane`], if it exists.
|
||||||
pub fn get(&self, pane: &Pane) -> Option<&T> {
|
pub fn get(&self, pane: Pane) -> Option<&T> {
|
||||||
self.panes.get(pane)
|
self.panes.get(&pane)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the internal state of the given [`Pane`] with mutability, if it
|
/// Returns the internal state of the given [`Pane`] with mutability, if it
|
||||||
/// exists.
|
/// exists.
|
||||||
pub fn get_mut(&mut self, pane: &Pane) -> Option<&mut T> {
|
pub fn get_mut(&mut self, pane: Pane) -> Option<&mut T> {
|
||||||
self.panes.get_mut(pane)
|
self.panes.get_mut(&pane)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over all the panes of the [`State`], alongside its
|
/// Returns an iterator over all the panes of the [`State`], alongside its
|
||||||
|
|
@ -104,13 +104,13 @@ impl<T> State<T> {
|
||||||
|
|
||||||
/// Returns the adjacent [`Pane`] of another [`Pane`] in the given
|
/// Returns the adjacent [`Pane`] of another [`Pane`] in the given
|
||||||
/// direction, if there is one.
|
/// direction, if there is one.
|
||||||
pub fn adjacent(&self, pane: &Pane, direction: Direction) -> Option<Pane> {
|
pub fn adjacent(&self, pane: Pane, direction: Direction) -> Option<Pane> {
|
||||||
let regions = self
|
let regions = self
|
||||||
.internal
|
.internal
|
||||||
.layout
|
.layout
|
||||||
.pane_regions(0.0, Size::new(4096.0, 4096.0));
|
.pane_regions(0.0, Size::new(4096.0, 4096.0));
|
||||||
|
|
||||||
let current_region = regions.get(pane)?;
|
let current_region = regions.get(&pane)?;
|
||||||
|
|
||||||
let target = match direction {
|
let target = match direction {
|
||||||
Direction::Left => {
|
Direction::Left => {
|
||||||
|
|
@ -142,7 +142,7 @@ impl<T> State<T> {
|
||||||
pub fn split(
|
pub fn split(
|
||||||
&mut self,
|
&mut self,
|
||||||
axis: Axis,
|
axis: Axis,
|
||||||
pane: &Pane,
|
pane: Pane,
|
||||||
state: T,
|
state: T,
|
||||||
) -> Option<(Pane, Split)> {
|
) -> Option<(Pane, Split)> {
|
||||||
self.split_node(axis, Some(pane), state, false)
|
self.split_node(axis, Some(pane), state, false)
|
||||||
|
|
@ -151,7 +151,7 @@ impl<T> State<T> {
|
||||||
/// Split a target [`Pane`] with a given [`Pane`] on a given [`Region`].
|
/// Split a target [`Pane`] with a given [`Pane`] on a given [`Region`].
|
||||||
///
|
///
|
||||||
/// Panes will be swapped by default for [`Region::Center`].
|
/// Panes will be swapped by default for [`Region::Center`].
|
||||||
pub fn split_with(&mut self, target: &Pane, pane: &Pane, region: Region) {
|
pub fn split_with(&mut self, target: Pane, pane: Pane, region: Region) {
|
||||||
match region {
|
match region {
|
||||||
Region::Center => self.swap(pane, target),
|
Region::Center => self.swap(pane, target),
|
||||||
Region::Edge(edge) => match edge {
|
Region::Edge(edge) => match edge {
|
||||||
|
|
@ -172,11 +172,11 @@ impl<T> State<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Drops the given [`Pane`] into the provided [`Target`].
|
/// Drops the given [`Pane`] into the provided [`Target`].
|
||||||
pub fn drop(&mut self, pane: &Pane, target: Target) {
|
pub fn drop(&mut self, pane: Pane, target: Target) {
|
||||||
match target {
|
match target {
|
||||||
Target::Edge(edge) => self.move_to_edge(pane, edge),
|
Target::Edge(edge) => self.move_to_edge(pane, edge),
|
||||||
Target::Pane(target, region) => {
|
Target::Pane(target, region) => {
|
||||||
self.split_with(&target, pane, region);
|
self.split_with(target, pane, region);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -184,7 +184,7 @@ impl<T> State<T> {
|
||||||
fn split_node(
|
fn split_node(
|
||||||
&mut self,
|
&mut self,
|
||||||
axis: Axis,
|
axis: Axis,
|
||||||
pane: Option<&Pane>,
|
pane: Option<Pane>,
|
||||||
state: T,
|
state: T,
|
||||||
inverse: bool,
|
inverse: bool,
|
||||||
) -> Option<(Pane, Split)> {
|
) -> Option<(Pane, Split)> {
|
||||||
|
|
@ -222,14 +222,14 @@ impl<T> State<T> {
|
||||||
fn split_and_swap(
|
fn split_and_swap(
|
||||||
&mut self,
|
&mut self,
|
||||||
axis: Axis,
|
axis: Axis,
|
||||||
target: &Pane,
|
target: Pane,
|
||||||
pane: &Pane,
|
pane: Pane,
|
||||||
swap: bool,
|
swap: bool,
|
||||||
) {
|
) {
|
||||||
if let Some((state, _)) = self.close(pane) {
|
if let Some((state, _)) = self.close(pane) {
|
||||||
if let Some((new_pane, _)) = self.split(axis, target, state) {
|
if let Some((new_pane, _)) = self.split(axis, target, state) {
|
||||||
if swap {
|
if swap {
|
||||||
self.swap(target, &new_pane);
|
self.swap(target, new_pane);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -238,7 +238,7 @@ impl<T> State<T> {
|
||||||
/// Move [`Pane`] to an [`Edge`] of the [`PaneGrid`].
|
/// Move [`Pane`] to an [`Edge`] of the [`PaneGrid`].
|
||||||
///
|
///
|
||||||
/// [`PaneGrid`]: super::PaneGrid
|
/// [`PaneGrid`]: super::PaneGrid
|
||||||
pub fn move_to_edge(&mut self, pane: &Pane, edge: Edge) {
|
pub fn move_to_edge(&mut self, pane: Pane, edge: Edge) {
|
||||||
match edge {
|
match edge {
|
||||||
Edge::Top => {
|
Edge::Top => {
|
||||||
self.split_major_node_and_swap(Axis::Horizontal, pane, true);
|
self.split_major_node_and_swap(Axis::Horizontal, pane, true);
|
||||||
|
|
@ -258,7 +258,7 @@ impl<T> State<T> {
|
||||||
fn split_major_node_and_swap(
|
fn split_major_node_and_swap(
|
||||||
&mut self,
|
&mut self,
|
||||||
axis: Axis,
|
axis: Axis,
|
||||||
pane: &Pane,
|
pane: Pane,
|
||||||
swap: bool,
|
swap: bool,
|
||||||
) {
|
) {
|
||||||
if let Some((state, _)) = self.close(pane) {
|
if let Some((state, _)) = self.close(pane) {
|
||||||
|
|
@ -273,14 +273,14 @@ impl<T> State<T> {
|
||||||
///
|
///
|
||||||
/// [`PaneGrid`]: super::PaneGrid
|
/// [`PaneGrid`]: super::PaneGrid
|
||||||
/// [`DragEvent`]: super::DragEvent
|
/// [`DragEvent`]: super::DragEvent
|
||||||
pub fn swap(&mut self, a: &Pane, b: &Pane) {
|
pub fn swap(&mut self, a: Pane, b: Pane) {
|
||||||
self.internal.layout.update(&|node| match node {
|
self.internal.layout.update(&|node| match node {
|
||||||
Node::Split { .. } => {}
|
Node::Split { .. } => {}
|
||||||
Node::Pane(pane) => {
|
Node::Pane(pane) => {
|
||||||
if pane == a {
|
if *pane == a {
|
||||||
*node = Node::Pane(*b);
|
*node = Node::Pane(b);
|
||||||
} else if pane == b {
|
} else if *pane == b {
|
||||||
*node = Node::Pane(*a);
|
*node = Node::Pane(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -296,19 +296,19 @@ impl<T> State<T> {
|
||||||
///
|
///
|
||||||
/// [`PaneGrid`]: super::PaneGrid
|
/// [`PaneGrid`]: super::PaneGrid
|
||||||
/// [`ResizeEvent`]: super::ResizeEvent
|
/// [`ResizeEvent`]: super::ResizeEvent
|
||||||
pub fn resize(&mut self, split: &Split, ratio: f32) {
|
pub fn resize(&mut self, split: Split, ratio: f32) {
|
||||||
let _ = self.internal.layout.resize(split, ratio);
|
let _ = self.internal.layout.resize(split, ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Closes the given [`Pane`] and returns its internal state and its closest
|
/// Closes the given [`Pane`] and returns its internal state and its closest
|
||||||
/// sibling, if it exists.
|
/// sibling, if it exists.
|
||||||
pub fn close(&mut self, pane: &Pane) -> Option<(T, Pane)> {
|
pub fn close(&mut self, pane: Pane) -> Option<(T, Pane)> {
|
||||||
if self.maximized == Some(*pane) {
|
if self.maximized == Some(pane) {
|
||||||
let _ = self.maximized.take();
|
let _ = self.maximized.take();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(sibling) = self.internal.layout.remove(pane) {
|
if let Some(sibling) = self.internal.layout.remove(pane) {
|
||||||
self.panes.remove(pane).map(|state| (state, sibling))
|
self.panes.remove(&pane).map(|state| (state, sibling))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
@ -318,8 +318,8 @@ impl<T> State<T> {
|
||||||
/// [`PaneGrid`] until [`Self::restore()`] is called.
|
/// [`PaneGrid`] until [`Self::restore()`] is called.
|
||||||
///
|
///
|
||||||
/// [`PaneGrid`]: super::PaneGrid
|
/// [`PaneGrid`]: super::PaneGrid
|
||||||
pub fn maximize(&mut self, pane: &Pane) {
|
pub fn maximize(&mut self, pane: Pane) {
|
||||||
self.maximized = Some(*pane);
|
self.maximized = Some(pane);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Restore the currently maximized [`Pane`] to it's normal size. All panes
|
/// Restore the currently maximized [`Pane`] to it's normal size. All panes
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue