refactor: use Slab for storing page section descriptions

This commit is contained in:
Michael Aaron Murphy 2024-06-06 15:52:21 +02:00
parent 17a74a512b
commit f6e50f1d9b
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
24 changed files with 666 additions and 639 deletions

View file

@ -12,4 +12,5 @@ generator = "0.7.5"
downcast-rs = "1.2.0"
once_cell = "1.19.0"
tokio.workspace = true
url = "2.5.0"
url = "2.5.0"
slab = "0.4.9"

View file

@ -3,7 +3,7 @@
use derive_setters::Setters;
use regex::Regex;
use std::borrow::Cow;
use slab::Slab;
use crate::{Binder, Page};
@ -31,7 +31,7 @@ pub struct Section<Message> {
#[setters(into)]
pub title: String,
#[setters(into)]
pub descriptions: Vec<Cow<'static, str>>,
pub descriptions: Slab<String>,
#[setters(skip)]
pub show_while: Option<ShowWhileFn<Message>>,
#[setters(skip)]
@ -44,7 +44,7 @@ impl<Message: 'static> Default for Section<Message> {
fn default() -> Self {
Self {
title: String::new(),
descriptions: Vec::new(),
descriptions: Slab::new(),
show_while: None,
view_fn: Box::new(unimplemented),
search_ignore: false,
@ -63,7 +63,7 @@ impl<Message: 'static> Section<Message> {
return true;
}
for description in &*self.descriptions {
for (_, description) in &self.descriptions {
if rule.is_match(description) {
return true;
}