Dynamic List
A versatile implementation of a dynamic bidirectional linked list in Rust, capable of storing any type. This fully-typed list eliminates the need for extra costs, such as dynamic dispatching, making it efficient and flexible for a wide range of use cases.
Installation 🚀
Add the following to your Cargo.toml:
[]
= "0.2.0"
Or if you want to use the latest version from the master branch:
[]
= { = "https://github.com/ferranSanchezLlado/dynamic-list.git" }
Usage 🛠️
The main way to interact with the DynamicList is through the implementation of a trait that allows it to iterate, reduce, or accumulate by recursively calling itself.
Example 1: Get a specific element
use *;
use *;
let list = list!;
assert_eq!;
assert_eq!;
Example 2: We want to concatenate a list of items into a single string:
use *;
// Iterator trait
let list = list!;
assert_eq!;
assert_eq!;
Example 3: We want to count how many even numbers are on the list:
use *;
// Polymorphic trait
// Iterator trait
let list = list!;
assert_eq!;
Limitations ⚠️
While Dynamic List provides a powerful and flexible solution, it's essential to be aware of the following limitations:
- Trait Implementation Requirement: To leverage the full functionality of the list, it's necessary for the values in the list to implement the required traits. Attempting to call trait methods on types that don't implement them will result in compilation errors that are hard to understand. However, with the future introduction of trait specialization in Rust, this limitation may be mitigated, allowing for more versatile trait implementations. For example, it would be possible to define a default value all types excluding the ones you are interested.
- Heap Allocation: Currently, elements in the list are allocated on the heap. Although this allows the possibility of avoiding the need to clone values in the list. If heap allocation is a concern, an alternative implementation allowing for single-directional allocation could be considered.
License 📄
This project is licensed under the MIT License or Apache License, Version 2.0 at your option.