wip: borrow checker battles

This commit is contained in:
🪞👃🪞 2024-09-04 16:57:48 +03:00
parent 1d4db3c629
commit 7fbb40fad6
38 changed files with 778 additions and 708 deletions

View file

@ -1,7 +1,7 @@
use crate::*;
/// A component that may contain [Focusable] components.
pub trait Focus <const N: usize, T, U>: Render<T, U> + Handle {
pub trait Focus <'a, const N: usize, T, U>: Render<'a, T, U> + Handle {
fn focus (&self) -> usize;
fn focus_mut (&mut self) -> &mut usize;
fn focusable (&self) -> [&dyn Focusable<T, U>;N];
@ -33,13 +33,13 @@ pub trait Focus <const N: usize, T, U>: Render<T, U> + Handle {
}
/// A component that may be focused.
pub trait Focusable<T, U>: Render<T, U> + Handle {
pub trait Focusable<'a, T, U>: Render<'a, T, U> + Handle {
fn is_focused (&self) -> bool;
fn set_focused (&mut self, focused: bool);
}
impl<F: Focusable<T, U>, T, U> Focusable<T, U> for Option<F>
where Option<F>: Render<T, U>
impl<'a, F: Focusable<'a, T, U>, T, U> Focusable<'a, T, U> for Option<F>
where Option<F>: Render<'a, T, U>
{
fn is_focused (&self) -> bool {
match self {
@ -59,21 +59,21 @@ impl<F: Focusable<T, U>, T, U> Focusable<T, U> for Option<F>
($struct:ident ($focus:ident) : $count:expr => [
$($focusable:ident),*
]) => {
impl Focus<$count> for $struct {
impl Focus<$count, T, U> for $struct {
fn focus (&self) -> usize {
self.$focus
}
fn focus_mut (&mut self) -> &mut usize {
&mut self.$focus
}
fn focusable (&self) -> [&dyn Focusable;$count] {
fn focusable (&self) -> [&dyn Focusable<T, U>;$count] {
[
$(&self.$focusable as &dyn Focusable,)*
$(&self.$focusable as &dyn Focusable<T, U>,)*
]
}
fn focusable_mut (&mut self) -> [&mut dyn Focusable;$count] {
fn focusable_mut (&mut self) -> [&mut dyn Focusable<T, U>;$count] {
[
$(&mut self.$focusable as &mut dyn Focusable,)*
$(&mut self.$focusable as &mut dyn Focusable<T, U>,)*
]
}
}