code: widget implementation, almost there

This commit is contained in:
2024-02-02 21:48:41 +01:00
parent e8ddfb25fa
commit 6e0a71b7de
18 changed files with 482 additions and 127 deletions
+61
View File
@@ -175,3 +175,64 @@ As I started by quickly using a django admin template with CSS to jump start the
I think it is important to go into form validation or interactive things quickly with htmx to properly sort out which to use.
### Builder Pattern etc.
// consider builder: https://docs.rs/derive_builder/latest/derive_builder/
// downside of builders as macro: no intellisense!
// each repository has to implement a repo info.
//#[derive(Builder)]
//#[builder(setter(into))]
#### static initializer
downside of a pub &'static str initializer struct is the rule to avoid any nested types that have any kind of building pattern, because you cannot properly move the data easily, especially if you want to move into enums, like an Option.
otherwise, self mutating building patterns can stay readonly either with the Copy trait and using self:
With "Copy":
fn self_mutating(mut self, value) -> Self {
self.value = value;
self
}
Without Copy:
fn self_mutating_manual(self, value) -> Self {
Struct {
value: value,
..self
}
}
However also works, but seems dirty:
fn self_mutating_instance_mut(&mut self, value) -> Self {
self.value = value;
*self
}
#### Cow
Other remarks: also useful is the usage of Cow, if you want to create internal objects that actuall reuse static data or take dynamic data.
use std::borrow::Cow;
#[derive(Debug, Serialize, Clone)]
pub struct Field {
pub widget: Cow<'static, str>,
pub label: Option<Cow<'static, str>>,
}
let static_field = Field::widget(Cow::Borrowed("/admin/widgets/input_text.jinja"));
let dynamic_label = String::from("Dynamic Label");
let dynamic_field = Field::widget(Cow::Owned(dynamic_label));
### Write article about "did you read the fineprint"
- The bleeding of lifetimes.
- 'static
- Send
- "object safe"
- the async dynamic dispatch.
- the building pattern debacle here