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