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

Download history 229/week @ 2024-08-26 386/week @ 2024-09-02 147/week @ 2024-09-09 167/week @ 2024-09-16 235/week @ 2024-09-23 144/week @ 2024-09-30 162/week @ 2024-10-07 153/week @ 2024-10-14 131/week @ 2024-10-21 374/week @ 2024-10-28 181/week @ 2024-11-04 145/week @ 2024-11-11 131/week @ 2024-11-18 149/week @ 2024-11-25 180/week @ 2024-12-02 372/week @ 2024-12-09

849 downloads per month
Used in 4 crates (via embedded-text)

MIT license

9KB
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.


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