| Crates.io | polyline-iter |
| lib.rs | polyline-iter |
| version | 0.3.2 |
| created_at | 2025-01-13 19:49:48.073831+00 |
| updated_at | 2026-01-15 21:42:58.419066+00 |
| description | Zero-dependency iterator-based Google Encoded Polyline encoder and decoder |
| homepage | |
| repository | https://github.com/kinkard/polyline-iter |
| max_upload_size | |
| id | 1515027 |
| size | 45,203 |
Zero-dependency Rust crate for encoding and decoding Google's polyline format.
Compared to the georust/polyline crate, the polyline-iter decodes polyline into an iterator over points instead of vector, which is benefitial when only a single iteration over the polyline is needed. And in such cases it performs twice as fast as the georust/polyline crate (check cargo bench for exact numbers) and has no hidden allocations.
Add this to your Cargo.toml:
[dependencies]
polyline-iter = "0.3"
let iter = polyline_iter::decode(6, "avs_iB}xlxWissBw|zEu``AsxgCyoaAm_z@");
assert_eq!(
iter.collect::<Vec<_>>(),
vec![
(55.585137, 12.999583),
(55.644854, 13.112187),
(55.678161, 13.182229),
(55.712222, 13.212444),
]
);
// Count points without collecting them
assert_eq!(polyline_iter::decode(5, "avs_iB}xlxWissBw|zEu``AsxgCyoaAm_z@").count(), 4);
// Iterator approach allows to transcode polyline to another precision without intermediate allocations.
let polyline5 = polyline_iter::encode(5, polyline_iter::decode(6, "avs_iB}xlxWissBw|zEu``AsxgCyoaAm_z@"));
assert_eq!(polyline5, "cngrIk~inAgtJw~TeoEwtL{sE{{D");
assert_eq!(
polyline_iter::decode(5, &polyline5).collect::<Vec<_>>(),
vec![
(55.58514, 12.99958),
(55.64486, 13.11218),
(55.67817, 13.18222),
(55.71223, 13.21244)
],
);
// Keeping all the power of working with slices
let points = vec![
(55.58513, 12.99958),
(55.61461, 13.04627),
(55.64485, 13.11219),
(55.67816, 13.18223),
(55.71840, 13.22343),
];
assert_eq!(polyline_iter::encode(5, points[1..3].iter().copied()), "ifmrIebsnA_|D_{K");
// This crate also provides encoding/decoding into binary format where URL-compatibility is not required
let polyline = polyline_iter::encode(5, points);
let binary = polyline_iter::encode_binary(5, points);
// Binary format is often 20-30% smaller than polyline format
assert!(binary.len() < polyline.len());
// Binary format is lossless if the same precision is used
let transcoded = polyline_iter::encode(5, polyline_iter::decode_binary(5, &binary));
assert_eq!(transcoded, polyline);
All code in this project is dual-licensed under either:
at your option.