all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [yew-devel] [PATCH proxmox-yew-widget-toolkit 1/1] store: implement FromIterator
@ 2025-01-22 15:49 Stefan Hanreich
  2025-01-25 16:57 ` [yew-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Hanreich @ 2025-01-22 15:49 UTC (permalink / raw)
  To: yew-devel

Enables better ergonomics for building stores from iterators and
is generally considered nice to have for structs representing some
form of collection.

For example:

```
self.store = Store::new();

store.set_data(
   it.collect()
);
```

vs

```
self.store = it.collect()
```

or

```
Store::from_iter(it)
```

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 src/state/store.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/state/store.rs b/src/state/store.rs
index e0ac683..11d7262 100644
--- a/src/state/store.rs
+++ b/src/state/store.rs
@@ -89,6 +89,18 @@ impl<T: ExtractPrimaryKey + 'static> Store<T> {
     }
 }
 
+impl<T: ExtractPrimaryKey + 'static> FromIterator<T> for Store<T> {
+    fn from_iter<A>(iter: A) -> Self
+    where
+        A: IntoIterator<Item = T>,
+    {
+        let store = Self::new();
+        store.set_data(iter.into_iter().collect());
+
+        store
+    }
+}
+
 impl<T: 'static> Store<T> {
     /// Creates a new instance with the specifies extract key function.
     pub fn with_extract_key(extract_key: impl Into<ExtractKeyFn<T>>) -> Self {
-- 
2.39.5


_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [yew-devel] applied: [PATCH proxmox-yew-widget-toolkit 1/1] store: implement FromIterator
  2025-01-22 15:49 [yew-devel] [PATCH proxmox-yew-widget-toolkit 1/1] store: implement FromIterator Stefan Hanreich
@ 2025-01-25 16:57 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2025-01-25 16:57 UTC (permalink / raw)
  To: Yew framework devel list at Proxmox, Stefan Hanreich

Am 22.01.25 um 16:49 schrieb Stefan Hanreich:
> Enables better ergonomics for building stores from iterators and
> is generally considered nice to have for structs representing some
> form of collection.
> 
> For example:
> 
> ```
> self.store = Store::new();
> 
> store.set_data(
>    it.collect()
> );
> ```
> 
> vs
> 
> ```
> self.store = it.collect()
> ```
> 
> or
> 
> ```
> Store::from_iter(it)
> ```
> 
> Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
> ---
>  src/state/store.rs | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
>

applied, thanks!


_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-01-25 16:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-22 15:49 [yew-devel] [PATCH proxmox-yew-widget-toolkit 1/1] store: implement FromIterator Stefan Hanreich
2025-01-25 16:57 ` [yew-devel] applied: " Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal