feat(core): format generated resources for templates
Implement Display for generated slots, keyed slots, atoms, and forms so public examples can pass typed resources directly to hemplate dynamic attributes and tests instead of extracting raw numeric ids. req: public_api/001 req: public_api/002
This commit is contained in:
@@ -730,6 +730,12 @@ impl<T> Clone for Slot<T> {
|
||||
|
||||
impl<T> Copy for Slot<T> {}
|
||||
|
||||
impl<T> core::fmt::Display for Slot<T> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
self.id.id.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Slot<T> {
|
||||
pub const fn new(id: u32) -> Self {
|
||||
Self {
|
||||
@@ -778,6 +784,12 @@ impl<K, T> Clone for KeyedSlot<K, T> {
|
||||
|
||||
impl<K, T> Copy for KeyedSlot<K, T> {}
|
||||
|
||||
impl<K, T> core::fmt::Display for KeyedSlot<K, T> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
self.id.id.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, T> KeyedSlot<K, T>
|
||||
where
|
||||
K: ToString,
|
||||
@@ -878,6 +890,12 @@ impl<T> Clone for Atom<T> {
|
||||
|
||||
impl<T> Copy for Atom<T> {}
|
||||
|
||||
impl<T> core::fmt::Display for Atom<T> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
self.id.id.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Atom<T> {
|
||||
pub const fn new(id: u32) -> Self {
|
||||
Self {
|
||||
@@ -951,6 +969,12 @@ impl<T> Clone for Form<T> {
|
||||
|
||||
impl<T> Copy for Form<T> {}
|
||||
|
||||
impl<T> core::fmt::Display for Form<T> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
self.id.id.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Form<T> {
|
||||
pub const fn new(id: u32) -> Self {
|
||||
Self {
|
||||
|
||||
@@ -102,9 +102,13 @@ fn component_refs_format_generated_component_names() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generated_handles_format_for_hemplate_dynamic_handle_attrs() {
|
||||
fn generated_resources_format_for_hemplate_dynamic_attrs() {
|
||||
// req: public_api/001 req: public_api/002
|
||||
assert_eq!(Slot::<String>::new(10).to_string(), "10");
|
||||
assert_eq!(KeyedSlot::<u64, String>::new(11).to_string(), "11");
|
||||
assert_eq!(Atom::<String>::new(12).to_string(), "12");
|
||||
assert_eq!(Handle::<()>::new(42).to_string(), "42");
|
||||
assert_eq!(Form::<()>::new(13).to_string(), "13");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user