4 releases
0.1.3 | Aug 15, 2021 |
---|---|
0.1.2 | Jul 12, 2021 |
0.1.1 | Mar 20, 2021 |
0.1.0 | Mar 15, 2021 |
#1775 in Data structures
849 downloads per month
Used in 4 crates
(via embedded-text)
9KB
185 lines
Object chain - build ad-hoc structures
Object chains are static objects whose type depends on the objects you store in them. This data structure is useful if you need to collect different objects that implement a common functionality and you don't want heap allocation.
To get started, you need to create a Chain
object by passing it your first object.
Use the append
method to add more objects to your chain.
If you need to pass the chain around, you can use impl ChainElement
or, if you need to be
explicit about the type, the chain!
macro.
If you want to access the elements inside, you'll need to implement a common trait for your objects
and an accessor interface for Chain
and Link
. You can see an example in the source code.
lib.rs
:
Create static chains of objects with different types.
In general, the chain starts (or ends, depending on your view) with a Chain
element
and is built up from any number of Link
s.
This basic structure only allows you
to query the number of elements, but you can implement a more useful trait for both Link
and
Chain
to make this structure more useful. For an example, check the
test_accessing_elements_with_common_interface
test in the source code.