feat(core): format handles for templates

Implement Display for generated Handle<T> values and migrate example view data to carry handles directly instead of raw handle id numbers for dynamic handle attributes.

req: public_api/001

req: public_api/002
This commit is contained in:
slhx agent
2026-05-26 00:30:23 +02:00
parent bc8534a768
commit a421865852
4 changed files with 30 additions and 18 deletions
+6
View File
@@ -896,6 +896,12 @@ impl<I> Handle<I> {
}
}
impl<I> core::fmt::Display for Handle<I> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.id.id.fmt(f)
}
}
pub trait FormValue {}
impl<T> FormValue for T where T: std::str::FromStr {}
+8 -2
View File
@@ -1,7 +1,7 @@
use slhx_core::{
event, navigate, redirect, replace, Atom, AtomSnapshot, AtomState, BuildFingerprint,
CssClass, CssClasses, Effect, EffectBatch, Form, IntoEffect, KeyedSlot, NavigateMode, Payload,
ResourceKind, SafeHtml, ScopeKey, Slot,
CssClass, CssClasses, Effect, EffectBatch, Form, Handle, IntoEffect, KeyedSlot, NavigateMode,
Payload, ResourceKind, SafeHtml, ScopeKey, Slot,
};
#[test]
@@ -93,6 +93,12 @@ fn slot_html_requires_explicit_safe_html() {
assert_eq!(payload, Payload::Html(String::from("<strong>ok</strong>")));
}
#[test]
fn generated_handles_format_for_hemplate_dynamic_handle_attrs() {
// req: public_api/001 req: public_api/002
assert_eq!(Handle::<()>::new(42).to_string(), "42");
}
#[test]
fn generated_css_classes_join_for_hemplate_dynamic_class_attrs() {
// req: style/003