#tuple #convert #vec #syntax

tuple-conv

Allows converting tuples of one element to vectors

2 stable releases

1.0.1 Sep 8, 2019
1.0.0 Sep 4, 2019

#2511 in Rust patterns

Download history 1824/week @ 2024-10-01 1305/week @ 2024-10-08 1315/week @ 2024-10-15 1672/week @ 2024-10-22 1680/week @ 2024-10-29 2093/week @ 2024-11-05 1864/week @ 2024-11-12 1827/week @ 2024-11-19 1488/week @ 2024-11-26 1489/week @ 2024-12-03 1601/week @ 2024-12-10 1569/week @ 2024-12-17 1276/week @ 2024-12-24 562/week @ 2024-12-31 1197/week @ 2025-01-07 1264/week @ 2025-01-14

4,553 downloads per month
Used in 7 crates (5 directly)

MIT license

14KB
157 lines

tuple-conv

License: MIT Docs Version Build Status

tuple-conv provides simple tools for converting tuples with repeated elements into vectors of that type. Repeated tuples are of the form: (T, T, ... T) - composed entirely of elements with type T.

More information can be found in the documentation.

Example

let t = (0, 1, 2);
let v = t.to_vec();
assert_eq!(v, [0, 1, 2]);

Motivation

The primary motivation for this package is syntactic elegance. In Python, we can easily convert tuples to lists with:

t = (1, 2, 3)
l = list(t)

This isn't typically possible in Rust, however, because each tuple is a distinct type. This isn't too bad, but repeated API calls warrant better syntax. tuple-conv provides a way of removing vec![] macro calls and get a bit more syntactical sugar without making every part of the public-facing API a macro.

Documentation

A more in-depth explanation is available at docs.rs

No runtime deps