Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zakstucke committed Feb 5, 2025
1 parent 0f30b86 commit 3421c8f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 59 deletions.
17 changes: 4 additions & 13 deletions router/src/flat_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl<Loc, Defs, FalFn, Fal> AddAnyAttr for FlatRoutesView<Loc, Defs, FalFn>
where
Loc: LocationProvider + Send,
Defs: MatchNestedRoutes + Send + 'static,
FalFn: FnOnce() -> Fal + Send,
FalFn: FnOnce() -> Fal + Send + 'static,
Fal: RenderHtml + 'static,
{
type Output<SomeNewAttr: leptos::attr::Attribute> =
Expand Down Expand Up @@ -427,11 +427,11 @@ impl<Loc, Defs, FalFn, Fal> RenderHtml for FlatRoutesView<Loc, Defs, FalFn>
where
Loc: LocationProvider + Send,
Defs: MatchNestedRoutes + Send + 'static,
FalFn: FnOnce() -> Fal + Send,
FalFn: FnOnce() -> Fal + Send + 'static,
Fal: RenderHtml + 'static,
{
type AsyncOutput = Self;
type Owned = FlatRoutesView<Loc, Defs, Box<dyn FnOnce() -> Fal + Send>>;
type Owned = Self;

const MIN_LENGTH: usize = <Either<Fal, AnyView> as RenderHtml>::MIN_LENGTH;

Expand Down Expand Up @@ -635,15 +635,6 @@ where
}

fn into_owned(self) -> Self::Owned {
let fallback = (self.fallback)();
FlatRoutesView {
current_url: self.current_url,
location: self.location,
routes: self.routes,
fallback: Box::new(move || fallback),
outer_owner: self.outer_owner,
set_is_routing: self.set_is_routing,
transition: self.transition,
}
self
}
}
22 changes: 6 additions & 16 deletions router/src/nested_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ where
impl<Loc, Defs, Fal, FalFn> AddAnyAttr for NestedRoutesView<Loc, Defs, FalFn>
where
Loc: LocationProvider + Send,
Defs: MatchNestedRoutes + Send + 'static, // TODO once the type erased AnyMatchNestedRoutes is merged with this branch, switch to that (adding 'static was a breaking change)
FalFn: FnOnce() -> Fal + Send,
Defs: MatchNestedRoutes + Send + 'static,
FalFn: FnOnce() -> Fal + Send + 'static,
Fal: RenderHtml + 'static,
{
type Output<SomeNewAttr: leptos::attr::Attribute> =
Expand All @@ -256,12 +256,12 @@ where
impl<Loc, Defs, FalFn, Fal> RenderHtml for NestedRoutesView<Loc, Defs, FalFn>
where
Loc: LocationProvider + Send,
Defs: MatchNestedRoutes + Send + 'static, // TODO once the type erased AnyMatchNestedRoutes is merged with this branch, switch to that (adding 'static was a breaking change)
FalFn: FnOnce() -> Fal + Send,
Defs: MatchNestedRoutes + Send + 'static,
FalFn: FnOnce() -> Fal + Send + 'static,
Fal: RenderHtml + 'static,
{
type AsyncOutput = Self;
type Owned = NestedRoutesView<Loc, Defs, Box<dyn FnOnce() -> Fal + Send>>;
type Owned = Self;

const MIN_LENGTH: usize = 0; // TODO

Expand Down Expand Up @@ -479,17 +479,7 @@ where
}

fn into_owned(self) -> Self::Owned {
let fal = (self.fallback)();
NestedRoutesView {
location: self.location,
routes: self.routes,
outer_owner: self.outer_owner,
current_url: self.current_url,
base: self.base,
fallback: Box::new(move || fal),
set_is_routing: self.set_is_routing,
transition: self.transition,
}
self
}
}

Expand Down
2 changes: 1 addition & 1 deletion tachys/src/html/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ where
} else {
2 // < ... >
+ E::TAG.len()
+ self.attributes.html_len()
+ self.attributes.html_len()
+ extra_attrs.map(|attrs| {
attrs.into_iter().map(Attribute::html_len).sum::<usize>()
}).unwrap_or(0)
Expand Down
36 changes: 22 additions & 14 deletions tachys/src/view/any_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,16 @@ where
}
}

/// TODO
/// Ignore, this is a hack for pre use<..> syntax.
/// https://github.com/rust-lang/rfcs/blob/master/text/3498-lifetime-capture-rules-2024.md#the-captures-trick
pub trait __Captures<T: ?Sized> {}
impl<T: ?Sized, U: ?Sized> __Captures<T> for U {}

/// A mutable view into the extra attributes stored in an [`AnyView`].
#[derive(Default)]
pub struct ExtraAttrsMut<'a>(Option<Vec<&'a mut Vec<AnyAttribute>>>);
impl<'a> ExtraAttrsMut<'a> {
/// TODO
/// Create a new mutable view from owned attributes.
pub fn from_owned(extra_attrs: &'a mut Option<Vec<AnyAttribute>>) -> Self {
match extra_attrs {
Some(extra_attrs) => {
Expand All @@ -375,8 +380,7 @@ impl<'a> ExtraAttrsMut<'a> {
}
}

/// TODO
pub fn add_layer<'b>(
fn add_layer<'b>(

Check warning on line 383 in tachys/src/view/any_view.rs

View workflow job for this annotation

GitHub Actions / autofix

method `add_layer` is never used

Check warning on line 383 in tachys/src/view/any_view.rs

View workflow job for this annotation

GitHub Actions / autofix

method `add_layer` is never used

Check warning on line 383 in tachys/src/view/any_view.rs

View workflow job for this annotation

GitHub Actions / autofix

method `add_layer` is never used

Check warning on line 383 in tachys/src/view/any_view.rs

View workflow job for this annotation

GitHub Actions / autofix

method `add_layer` is never used

Check warning on line 383 in tachys/src/view/any_view.rs

View workflow job for this annotation

GitHub Actions / autofix

method `add_layer` is never used

Check warning on line 383 in tachys/src/view/any_view.rs

View workflow job for this annotation

GitHub Actions / autofix

method `add_layer` is never used

Check warning on line 383 in tachys/src/view/any_view.rs

View workflow job for this annotation

GitHub Actions / autofix

method `add_layer` is never used

Check warning on line 383 in tachys/src/view/any_view.rs

View workflow job for this annotation

GitHub Actions / autofix

method `add_layer` is never used

Check warning on line 383 in tachys/src/view/any_view.rs

View workflow job for this annotation

GitHub Actions / autofix

method `add_layer` is never used

Check warning on line 383 in tachys/src/view/any_view.rs

View workflow job for this annotation

GitHub Actions / autofix

method `add_layer` is never used
mut self,
extra_attrs: &'b mut Vec<AnyAttribute>,
) -> ExtraAttrsMut<'b>
Expand All @@ -397,15 +401,16 @@ impl<'a> ExtraAttrsMut<'a> {
}
}

/// TODO
/// Check if there are any extra attributes.
pub fn is_some(&self) -> bool {
match &self.0 {
Some(extra) => extra.is_empty(),
None => true,
}
}

/// TODO
/// "clone" the mutable view, to allow reuse in e.g. a for loop.
/// The same as .as_deref_mut() on Option<&mut T>.
pub fn as_deref_mut(&mut self) -> ExtraAttrsMut<'_> {
ExtraAttrsMut(
self.0
Expand All @@ -414,10 +419,10 @@ impl<'a> ExtraAttrsMut<'a> {
)
}

/// TODO
/// Iterate over the extra attributes.
pub fn iter_mut(
&mut self,
) -> impl Iterator<Item = &mut AnyAttribute> + use<'_, 'a> {
) -> impl Iterator<Item = &mut AnyAttribute> + __Captures<&'a ()> + '_ {
match &mut self.0 {
Some(inner) => itertools::Either::Left(
inner.iter_mut().flat_map(|v| v.iter_mut()),
Expand All @@ -426,13 +431,16 @@ impl<'a> ExtraAttrsMut<'a> {
}
}

/// TODO
/// Call [`RenderHtml::resolve`] on any extra attributes in parallel.
pub async fn resolve(self) {
if let Some(extra_attrs) = self.0 {
for extra_attrs in extra_attrs {
*extra_attrs =
Attribute::resolve(std::mem::take(extra_attrs)).await;
}
if let Some(extra_attr_groups) = self.0 {
futures::future::join_all(extra_attr_groups.into_iter().map(
|extra_attrs| async move {
*extra_attrs =
Attribute::resolve(std::mem::take(extra_attrs)).await;
},
))
.await;
}
}
}
Expand Down
21 changes: 6 additions & 15 deletions tachys/src/view/keyed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ where

impl<T, I, K, KF, VF, VFS, V> AddAnyAttr for Keyed<T, I, K, KF, VF, VFS, V>
where
I: IntoIterator<Item = T> + Send,
I: IntoIterator<Item = T> + Send + 'static,
K: Eq + Hash + 'static,
KF: Fn(&T) -> K + Send + 'static,
V: RenderHtml,
V: 'static,
VF: Fn(usize, T) -> (VFS, V) + Send + 'static,
VFS: Fn(usize) + 'static,
T: Send + 'static,
T: 'static,
{
type Output<SomeNewAttr: Attribute> = Keyed<
T,
Expand Down Expand Up @@ -191,16 +191,16 @@ where

impl<T, I, K, KF, VF, VFS, V> RenderHtml for Keyed<T, I, K, KF, VF, VFS, V>
where
I: IntoIterator<Item = T> + Send,
I: IntoIterator<Item = T> + Send + 'static,
K: Eq + Hash + 'static,
KF: Fn(&T) -> K + Send + 'static,
V: RenderHtml + 'static,
VF: Fn(usize, T) -> (VFS, V) + Send + 'static,
VFS: Fn(usize) + 'static,
T: Send + 'static,
T: 'static,
{
type AsyncOutput = Vec<V::AsyncOutput>; // TODO
type Owned = Keyed<T, Vec<T>, K, KF, VF, VFS, V>;
type Owned = Keyed<T, I, K, KF, VF, VFS, V>;

const MIN_LENGTH: usize = 0;

Expand Down Expand Up @@ -315,16 +315,7 @@ where
}

fn into_owned(self) -> Self::Owned {
let Keyed {
items,
key_fn,
view_fn,
} = self;
Keyed {
items: items.into_iter().collect::<Vec<_>>(),
key_fn,
view_fn,
}
self
}
}

Expand Down

0 comments on commit 3421c8f

Please sign in to comment.