File tree Expand file tree Collapse file tree 2 files changed +116
-2
lines changed
Expand file tree Collapse file tree 2 files changed +116
-2
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,64 @@ Quick links to key API documentation:
5050|
5151[ Reduction] ( https://docs.rs/retriever/latest/retriever/types/reduction/struct.Reduction.html )
5252
53- ### Example
53+ ### Basic Example
54+
55+ In this example, we create a Storage of puppies from old American comic strips.
56+
57+ ``` rust
58+ use retriever :: prelude :: * ;
59+ use std :: borrow :: Cow ;
60+
61+ struct Puppy {
62+ name : String ,
63+ age : u64 ,
64+ }
65+
66+ impl Record <(),str > for Puppy {
67+ fn chunk_key (& self ) -> Cow <()> {
68+ Cow :: Owned (())
69+ }
70+
71+ fn item_key (& self ) -> Cow <str > {
72+ Cow :: Borrowed (& self . name)
73+ }
74+ }
75+
76+ let mut storage : Storage <(),str ,Puppy > = Storage :: new ();
77+
78+ storage . add (Puppy {
79+ name : " Snoopy" . to_string (),
80+ age : 70
81+ });
82+
83+ storage . add (Puppy {
84+ name : " Odie" . to_string (),
85+ age : 52 ,
86+ });
87+
88+ storage . add (Puppy {
89+ name : " Marmaduke" . to_string (),
90+ age : 66
91+ });
92+
93+ assert_eq! (
94+ Some (52 ),
95+ storage . get (& ID . item (" Odie" )). map (| puppy | puppy . age)
96+ );
97+
98+ assert_eq! (
99+ 3 ,
100+ storage . query (Everything ). count ()
101+ );
102+
103+ assert_eq! (
104+ 2 ,
105+ storage . query (Everything . filter (| puppy : & Puppy | puppy . age > 60 )). count ()
106+ );
107+
108+ ```
109+
110+ ### Extended Example
54111
55112``` rust
56113use retriever :: prelude :: * ;
Original file line number Diff line number Diff line change 5252//! |
5353//! [Reduction](https://docs.rs/retriever/latest/retriever/types/reduction/struct.Reduction.html)
5454//!
55- //! ## Example
55+ //! ## Basic Example
56+ //!
57+ //! In this example, we create a Storage of puppies from old American comic strips.
58+ //!
59+ //! ```
60+ //! use retriever::prelude::*;
61+ //! use std::borrow::Cow;
62+ //!
63+ //! struct Puppy {
64+ //! name: String,
65+ //! age: u64,
66+ //! }
67+ //!
68+ //! impl Record<(),str> for Puppy {
69+ //! fn chunk_key(&self) -> Cow<()> {
70+ //! Cow::Owned(())
71+ //! }
72+ //!
73+ //! fn item_key(&self) -> Cow<str> {
74+ //! Cow::Borrowed(&self.name)
75+ //! }
76+ //! }
77+ //!
78+ //! let mut storage : Storage<(),str,Puppy> = Storage::new();
79+ //!
80+ //! storage.add(Puppy {
81+ //! name: "Snoopy".to_string(),
82+ //! age: 70
83+ //! });
84+ //!
85+ //! storage.add(Puppy {
86+ //! name: "Odie".to_string(),
87+ //! age: 52,
88+ //! });
89+ //!
90+ //! storage.add(Puppy {
91+ //! name: "Marmaduke".to_string(),
92+ //! age: 66
93+ //! });
94+ //!
95+ //! assert_eq!(
96+ //! Some(52),
97+ //! storage.get(&ID.item("Odie")).map(|puppy| puppy.age)
98+ //! );
99+ //!
100+ //! assert_eq!(
101+ //! 3,
102+ //! storage.query(Everything).count()
103+ //! );
104+ //!
105+ //! assert_eq!(
106+ //! 2,
107+ //! storage.query(Everything.filter(|puppy: &Puppy| puppy.age > 60)).count()
108+ //! );
109+ //!
110+ //! ```
111+ //!
112+ //! ## Extended Example
56113//!
57114//! ```
58115//! use retriever::prelude::*;
You can’t perform that action at this time.
0 commit comments