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]
|
||||
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 {
|
||||
fn next(&self) -> Kind {
|
||||
fn next(self) -> Kind {
|
||||
match self {
|
||||
Kind::Single => Kind::Double,
|
||||
Kind::Double => Kind::Triple,
|
||||
|
|
|
|||
|
|
@ -61,11 +61,8 @@ impl Application for Example {
|
|||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
match message {
|
||||
Message::Split(axis, pane) => {
|
||||
let result = self.panes.split(
|
||||
axis,
|
||||
&pane,
|
||||
Pane::new(self.panes_created),
|
||||
);
|
||||
let result =
|
||||
self.panes.split(axis, pane, Pane::new(self.panes_created));
|
||||
|
||||
if let Some((pane, _)) = result {
|
||||
self.focus = Some(pane);
|
||||
|
|
@ -77,7 +74,7 @@ impl Application for Example {
|
|||
if let Some(pane) = self.focus {
|
||||
let result = self.panes.split(
|
||||
axis,
|
||||
&pane,
|
||||
pane,
|
||||
Pane::new(self.panes_created),
|
||||
);
|
||||
|
||||
|
|
@ -90,8 +87,7 @@ impl Application for Example {
|
|||
}
|
||||
Message::FocusAdjacent(direction) => {
|
||||
if let Some(pane) = self.focus {
|
||||
if let Some(adjacent) =
|
||||
self.panes.adjacent(&pane, direction)
|
||||
if let Some(adjacent) = self.panes.adjacent(pane, direction)
|
||||
{
|
||||
self.focus = Some(adjacent);
|
||||
}
|
||||
|
|
@ -101,37 +97,34 @@ impl Application for Example {
|
|||
self.focus = Some(pane);
|
||||
}
|
||||
Message::Resized(pane_grid::ResizeEvent { split, ratio }) => {
|
||||
self.panes.resize(&split, ratio);
|
||||
self.panes.resize(split, ratio);
|
||||
}
|
||||
Message::Dragged(pane_grid::DragEvent::Dropped {
|
||||
pane,
|
||||
target,
|
||||
}) => {
|
||||
self.panes.drop(&pane, target);
|
||||
self.panes.drop(pane, target);
|
||||
}
|
||||
Message::Dragged(_) => {}
|
||||
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;
|
||||
}
|
||||
}
|
||||
Message::Maximize(pane) => self.panes.maximize(&pane),
|
||||
Message::Maximize(pane) => self.panes.maximize(pane),
|
||||
Message::Restore => {
|
||||
self.panes.restore();
|
||||
}
|
||||
Message::Close(pane) => {
|
||||
if let Some((_, sibling)) = self.panes.close(&pane) {
|
||||
if let Some((_, sibling)) = self.panes.close(pane) {
|
||||
self.focus = Some(sibling);
|
||||
}
|
||||
}
|
||||
Message::CloseFocused => {
|
||||
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 let Some((_, sibling)) = self.panes.close(&pane)
|
||||
{
|
||||
if let Some((_, sibling)) = self.panes.close(pane) {
|
||||
self.focus = Some(sibling);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -443,7 +443,7 @@ pub enum Filter {
|
|||
}
|
||||
|
||||
impl Filter {
|
||||
fn matches(&self, task: &Task) -> bool {
|
||||
fn matches(self, task: &Task) -> bool {
|
||||
match self {
|
||||
Filter::All => true,
|
||||
Filter::Active => !task.completed,
|
||||
|
|
|
|||
|
|
@ -95,13 +95,13 @@ impl Node {
|
|||
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 {
|
||||
Node::Split { a, b, .. } => {
|
||||
a.find(pane).or_else(move || b.find(pane))
|
||||
}
|
||||
Node::Pane(p) => {
|
||||
if p == pane {
|
||||
if *p == pane {
|
||||
Some(self)
|
||||
} else {
|
||||
None
|
||||
|
|
@ -139,12 +139,12 @@ impl Node {
|
|||
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 {
|
||||
Node::Split {
|
||||
id, ratio, a, b, ..
|
||||
} => {
|
||||
if id == split {
|
||||
if *id == split {
|
||||
*ratio = percentage;
|
||||
|
||||
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 {
|
||||
Node::Split { a, b, .. } => {
|
||||
if a.pane() == Some(*pane) {
|
||||
if a.pane() == Some(pane) {
|
||||
*self = *b.clone();
|
||||
Some(self.first_pane())
|
||||
} else if b.pane() == Some(*pane) {
|
||||
} else if b.pane() == Some(pane) {
|
||||
*self = *a.clone();
|
||||
Some(self.first_pane())
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -75,14 +75,14 @@ impl<T> State<T> {
|
|||
}
|
||||
|
||||
/// Returns the internal state of the given [`Pane`], if it exists.
|
||||
pub fn get(&self, pane: &Pane) -> Option<&T> {
|
||||
self.panes.get(pane)
|
||||
pub fn get(&self, pane: Pane) -> Option<&T> {
|
||||
self.panes.get(&pane)
|
||||
}
|
||||
|
||||
/// Returns the internal state of the given [`Pane`] with mutability, if it
|
||||
/// exists.
|
||||
pub fn get_mut(&mut self, pane: &Pane) -> Option<&mut T> {
|
||||
self.panes.get_mut(pane)
|
||||
pub fn get_mut(&mut self, pane: Pane) -> Option<&mut T> {
|
||||
self.panes.get_mut(&pane)
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// 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
|
||||
.internal
|
||||
.layout
|
||||
.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 {
|
||||
Direction::Left => {
|
||||
|
|
@ -142,7 +142,7 @@ impl<T> State<T> {
|
|||
pub fn split(
|
||||
&mut self,
|
||||
axis: Axis,
|
||||
pane: &Pane,
|
||||
pane: Pane,
|
||||
state: T,
|
||||
) -> Option<(Pane, Split)> {
|
||||
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`].
|
||||
///
|
||||
/// 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 {
|
||||
Region::Center => self.swap(pane, target),
|
||||
Region::Edge(edge) => match edge {
|
||||
|
|
@ -172,11 +172,11 @@ impl<T> State<T> {
|
|||
}
|
||||
|
||||
/// 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 {
|
||||
Target::Edge(edge) => self.move_to_edge(pane, edge),
|
||||
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(
|
||||
&mut self,
|
||||
axis: Axis,
|
||||
pane: Option<&Pane>,
|
||||
pane: Option<Pane>,
|
||||
state: T,
|
||||
inverse: bool,
|
||||
) -> Option<(Pane, Split)> {
|
||||
|
|
@ -222,14 +222,14 @@ impl<T> State<T> {
|
|||
fn split_and_swap(
|
||||
&mut self,
|
||||
axis: Axis,
|
||||
target: &Pane,
|
||||
pane: &Pane,
|
||||
target: Pane,
|
||||
pane: Pane,
|
||||
swap: bool,
|
||||
) {
|
||||
if let Some((state, _)) = self.close(pane) {
|
||||
if let Some((new_pane, _)) = self.split(axis, target, state) {
|
||||
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`].
|
||||
///
|
||||
/// [`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 {
|
||||
Edge::Top => {
|
||||
self.split_major_node_and_swap(Axis::Horizontal, pane, true);
|
||||
|
|
@ -258,7 +258,7 @@ impl<T> State<T> {
|
|||
fn split_major_node_and_swap(
|
||||
&mut self,
|
||||
axis: Axis,
|
||||
pane: &Pane,
|
||||
pane: Pane,
|
||||
swap: bool,
|
||||
) {
|
||||
if let Some((state, _)) = self.close(pane) {
|
||||
|
|
@ -273,14 +273,14 @@ impl<T> State<T> {
|
|||
///
|
||||
/// [`PaneGrid`]: super::PaneGrid
|
||||
/// [`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 {
|
||||
Node::Split { .. } => {}
|
||||
Node::Pane(pane) => {
|
||||
if pane == a {
|
||||
*node = Node::Pane(*b);
|
||||
} else if pane == b {
|
||||
*node = Node::Pane(*a);
|
||||
if *pane == a {
|
||||
*node = Node::Pane(b);
|
||||
} else if *pane == b {
|
||||
*node = Node::Pane(a);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -296,19 +296,19 @@ impl<T> State<T> {
|
|||
///
|
||||
/// [`PaneGrid`]: super::PaneGrid
|
||||
/// [`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);
|
||||
}
|
||||
|
||||
/// Closes the given [`Pane`] and returns its internal state and its closest
|
||||
/// sibling, if it exists.
|
||||
pub fn close(&mut self, pane: &Pane) -> Option<(T, Pane)> {
|
||||
if self.maximized == Some(*pane) {
|
||||
pub fn close(&mut self, pane: Pane) -> Option<(T, Pane)> {
|
||||
if self.maximized == Some(pane) {
|
||||
let _ = self.maximized.take();
|
||||
}
|
||||
|
||||
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 {
|
||||
None
|
||||
}
|
||||
|
|
@ -318,8 +318,8 @@ impl<T> State<T> {
|
|||
/// [`PaneGrid`] until [`Self::restore()`] is called.
|
||||
///
|
||||
/// [`PaneGrid`]: super::PaneGrid
|
||||
pub fn maximize(&mut self, pane: &Pane) {
|
||||
self.maximized = Some(*pane);
|
||||
pub fn maximize(&mut self, pane: Pane) {
|
||||
self.maximized = Some(pane);
|
||||
}
|
||||
|
||||
/// Restore the currently maximized [`Pane`] to it's normal size. All panes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue