all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pdm-devel] [PATCH proxmox-yew-widget-toolkit 1/1] store: implement FromIterator
@ 2025-01-22 15:47 Stefan Hanreich
  2025-01-22 15:48 ` Stefan Hanreich
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Hanreich @ 2025-01-22 15:47 UTC (permalink / raw)
  To: pdm-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


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


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

* Re: [pdm-devel] [PATCH proxmox-yew-widget-toolkit 1/1] store: implement FromIterator
  2025-01-22 15:47 [pdm-devel] [PATCH proxmox-yew-widget-toolkit 1/1] store: implement FromIterator Stefan Hanreich
@ 2025-01-22 15:48 ` Stefan Hanreich
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hanreich @ 2025-01-22 15:48 UTC (permalink / raw)
  To: pdm-devel

wrong mailing list - sorry for the noise


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


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

end of thread, other threads:[~2025-01-22 15:48 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:47 [pdm-devel] [PATCH proxmox-yew-widget-toolkit 1/1] store: implement FromIterator Stefan Hanreich
2025-01-22 15:48 ` Stefan Hanreich

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