Elimina downcast_rs y codifica componentes con Any
This commit is contained in:
parent
13c2e77688
commit
6de248f630
16 changed files with 60 additions and 9 deletions
|
|
@ -24,7 +24,6 @@ categories = [
|
|||
[dependencies]
|
||||
concat-string = "1.0.1"
|
||||
doc-comment = "0.3.3"
|
||||
downcast-rs = "1.2.0"
|
||||
figlet-rs = "0.1.3"
|
||||
futures = "0.3.21"
|
||||
once_cell = "1.10.0"
|
||||
|
|
|
|||
|
|
@ -45,6 +45,10 @@ impl PageComponent for Block {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Block {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ impl PageComponent for Chunck {
|
|||
fn default_render(&self, _: &mut PageAssets) -> Markup {
|
||||
html! { (*self.html()) }
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Chunck {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,10 @@ impl PageComponent for Container {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Container {
|
||||
|
|
|
|||
|
|
@ -65,6 +65,10 @@ impl PageComponent for Button {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Button {
|
||||
|
|
|
|||
|
|
@ -84,6 +84,10 @@ impl PageComponent for Date {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Date {
|
||||
|
|
|
|||
|
|
@ -54,6 +54,10 @@ impl PageComponent for Form {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Form {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ impl PageComponent for Hidden {
|
|||
input type="hidden" id=[id] name=[self.name()] value=[self.value()];
|
||||
}
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Hidden {
|
||||
|
|
|
|||
|
|
@ -112,6 +112,10 @@ impl PageComponent for Input {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Input {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ impl PageComponent for Column {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Column {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ impl PageComponent for Row {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Row {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ impl PageComponent for Image {
|
|||
class=[self.classes()];
|
||||
}
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Image {
|
||||
|
|
|
|||
|
|
@ -67,6 +67,10 @@ impl PageComponent for MenuItem {
|
|||
MenuItemType::Void => html! {},
|
||||
}
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl MenuItem {
|
||||
|
|
@ -217,6 +221,10 @@ impl PageComponent for Menu {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Menu {
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ impl ThemeTrait for BulmixTheme {
|
|||
) {
|
||||
match component.name() {
|
||||
"GridRow" => {
|
||||
let row = component.downcast_mut::<grid::Row>().unwrap();
|
||||
let row = component.as_mut_any().downcast_mut::<grid::Row>().unwrap();
|
||||
row.alter_classes("columns", ClassesOp::SetDefault);
|
||||
},
|
||||
"GridColumn" => {
|
||||
let col = component.downcast_mut::<grid::Column>().unwrap();
|
||||
let col = component.as_mut_any().downcast_mut::<grid::Column>().unwrap();
|
||||
col.alter_classes("column", ClassesOp::SetDefault);
|
||||
},
|
||||
_ => {},
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use crate::html::{Markup, html};
|
||||
use crate::response::page::PageAssets;
|
||||
|
||||
use downcast_rs::{Downcast, impl_downcast};
|
||||
|
||||
use std::any::type_name;
|
||||
|
||||
pub trait PageComponent: Downcast + Send + Sync {
|
||||
pub use std::any::Any as AnyComponent;
|
||||
|
||||
pub trait PageComponent: AnyComponent + Send + Sync {
|
||||
|
||||
fn new() -> Self where Self: Sized;
|
||||
|
||||
|
|
@ -41,6 +41,6 @@ pub trait PageComponent: Downcast + Send + Sync {
|
|||
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
||||
html! {}
|
||||
}
|
||||
}
|
||||
|
||||
impl_downcast!(PageComponent);
|
||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ pub use assets::{
|
|||
};
|
||||
|
||||
mod component;
|
||||
pub use component::PageComponent;
|
||||
pub use component::{AnyComponent, PageComponent};
|
||||
|
||||
mod container;
|
||||
pub use container::PageContainer;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue