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

#1684 in Data structures

Download history 144/week @ 2023-12-04 62/week @ 2023-12-11 73/week @ 2023-12-18 58/week @ 2023-12-25 95/week @ 2024-01-01 80/week @ 2024-01-08 115/week @ 2024-01-15 107/week @ 2024-01-22 187/week @ 2024-01-29 174/week @ 2024-02-05 181/week @ 2024-02-12 222/week @ 2024-02-19 253/week @ 2024-02-26 235/week @ 2024-03-04 151/week @ 2024-03-11 143/week @ 2024-03-18

819 downloads per month
Used in 2 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