#chain #object #ad-hoc

no-std object-chain

Ad-hoc structure builder

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

#1186 in Data structures

Download history 175/week @ 2023-06-03 27/week @ 2023-06-10 100/week @ 2023-06-17 109/week @ 2023-06-24 112/week @ 2023-07-01 62/week @ 2023-07-08 121/week @ 2023-07-15 69/week @ 2023-07-22 53/week @ 2023-07-29 58/week @ 2023-08-05 104/week @ 2023-08-12 265/week @ 2023-08-19 193/week @ 2023-08-26 196/week @ 2023-09-02 111/week @ 2023-09-09 73/week @ 2023-09-16

583 downloads per month
Used in 2 crates (via embedded-text)

MIT license

185 lines

Object chain - build ad-hoc structures crates.io docs.rs

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.


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 Links.

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.

No runtime deps