summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2026-06-18 23:52:39 -0700
committerMike Buland <mike@xagasoft.com>2026-06-18 23:52:39 -0700
commita7ae82db8aef8b327e893a4619346ad59b2ed895 (patch)
treebc1d810b425c274d823a9d9256e86c65ed51be0b
parent00ffb6d11ed3a1d6508cbf065679b6f04673f238 (diff)
downloadcrimtag-a7ae82db8aef8b327e893a4619346ad59b2ed895.tar.gz
crimtag-a7ae82db8aef8b327e893a4619346ad59b2ed895.tar.bz2
crimtag-a7ae82db8aef8b327e893a4619346ad59b2ed895.tar.xz
crimtag-a7ae82db8aef8b327e893a4619346ad59b2ed895.zip
Almost there
-rw-r--r--src/context.rs2
-rw-r--r--src/lib.rs14
2 files changed, 16 insertions, 0 deletions
diff --git a/src/context.rs b/src/context.rs
index 83f8539..4de5b45 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -44,6 +44,8 @@ impl<'a> MappedStructure<'a> for Context {
44 44
45pub trait MappedList<'a> { 45pub trait MappedList<'a> {
46 fn get_index(&'a self, id: usize) -> Option<MappedValue<'a>>; 46 fn get_index(&'a self, id: usize) -> Option<MappedValue<'a>>;
47// fn get_iterator(&'a self) -> MappedListIterator<'a>;
48 fn for_each(&'a self, func: &dyn Fn(&MappedValue<'a>));
47} 49}
48 50
49pub enum MappedValue<'a> { 51pub enum MappedValue<'a> {
diff --git a/src/lib.rs b/src/lib.rs
index eda2f31..b682ddc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -521,6 +521,12 @@ Now with explicit outputs:
521 None 521 None
522 } 522 }
523 } 523 }
524
525 fn for_each(&'a self, func: &dyn Fn(&MappedValue<'a>)) {
526 for i in self {
527 func( &MappedValue::Struct(i) );
528 }
529 }
524 } 530 }
525 531
526 #[test] 532 #[test]
@@ -530,6 +536,14 @@ Now with explicit outputs:
530 println!("{:?}", 536 println!("{:?}",
531 page.get_value(&"total_pages") 537 page.get_value(&"total_pages")
532 ); 538 );
539
540 if let Some(MappedValue::List(l)) = page.get_value(&"items") {
541 l.for_each(&|x: &MappedValue| {
542 if let MappedValue::Struct(s) = x {
543 println!(" - {:?}", s.get_value(&"title"));
544 }
545 });
546 }
533 Ok(()) 547 Ok(())
534 } 548 }
535} 549}