Skip to content

Commit a00ab44

Browse files
committed
Merge branch 'main' of github.com:MyJetTools/dioxus-admin-ui-kit
2 parents 48ce206 + 5788288 commit a00ab44

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,76 @@ let valid: bool = selector.validate();
232232

233233
Implement on your enum to use with `select_enum_value` / `select_enum_value_opt`.
234234

235+
**Standard pattern** (mirrors real project usage):
236+
237+
```rust
238+
use dioxus_admin_ui_kit::types::EnumIterator;
239+
use rust_extensions::AsStr;
240+
use serde::{Deserialize, Serialize};
241+
use std::str::FromStr;
242+
243+
// ✅ Required derives: Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize
244+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
245+
pub enum InstrumentType {
246+
#[default]
247+
Forex,
248+
Cfd,
249+
Crypto,
250+
}
251+
252+
impl InstrumentType {
253+
// ✅ ALL constant — used by EnumIterator::get_all()
254+
pub const ALL: &'static [Self] = &[Self::Forex, Self::Cfd, Self::Crypto];
255+
}
256+
257+
// ✅ AsStr — always implemented (used in both UI and non-UI contexts)
258+
impl AsStr for InstrumentType {
259+
fn as_str(&self) -> &'static str {
260+
match self {
261+
Self::Forex => "Forex",
262+
Self::Cfd => "CFD",
263+
Self::Crypto => "Crypto",
264+
}
265+
}
266+
}
267+
268+
impl FromStr for InstrumentType {
269+
type Err = ();
270+
fn from_str(s: &str) -> Result<Self, ()> {
271+
Self::ALL.iter().find(|v| v.as_str() == s).copied().ok_or(())
272+
}
273+
}
274+
275+
// ✅ EnumIterator — for dioxus UI selectors
276+
impl EnumIterator for InstrumentType {
277+
type TItem = Self;
278+
fn get_value(&self) -> Self { *self }
279+
fn get_all() -> &'static [Self] { Self::ALL }
280+
}
281+
```
282+
283+
**Calling `select_enum_value`** — pass value by **copy** (not reference):
284+
285+
```rust
286+
// ✅ CORRECT — InstrumentType is Copy
287+
select_enum_value("Type", cs_ra.tp, EventHandler::new(move |v: InstrumentType| cs.write().tp = v))
288+
289+
// ❌ WRONG — &cs_ra.tp doesn't satisfy EnumIterator bound
290+
select_enum_value("Type", &cs_ra.tp, ...)
291+
```
292+
293+
**Dependency**: `rust-extensions` must be a **direct** dependency in `Cargo.toml` (not via `service-sdk`), because `service-sdk` is `optional = true` (server feature only) and enum types are used on the web side too:
294+
295+
```toml
296+
rust-extensions = { tag = "0.1.5", git = "https://github.com/MyJetTools/rust-extensions.git" }
297+
```
298+
299+
---
300+
301+
### `EnumIterator` trait — original minimal example
302+
303+
Implement on your enum to use with `select_enum_value` / `select_enum_value_opt`.
304+
235305
```rust
236306
use dioxus_admin_ui_kit::types::EnumIterator;
237307
use rust_extensions::AsStr;

0 commit comments

Comments
 (0)