#string #concat #push

concat-in-place

Efficient macros for concatenation of strings and vectors

2 stable releases

1.1.0 Feb 27, 2022
1.0.0 Jan 27, 2020

#672 in Rust patterns

Download history 751/week @ 2024-07-21 690/week @ 2024-07-28 1564/week @ 2024-08-04 1490/week @ 2024-08-11 845/week @ 2024-08-18 587/week @ 2024-08-25 772/week @ 2024-09-01 688/week @ 2024-09-08 515/week @ 2024-09-15 784/week @ 2024-09-22 581/week @ 2024-09-29 568/week @ 2024-10-06 565/week @ 2024-10-13 347/week @ 2024-10-20 573/week @ 2024-10-27 342/week @ 2024-11-03

1,889 downloads per month

MIT/Apache

8KB
68 lines

concat-in-place

Crates.io Docs.rs

Provides efficient concatenation of strings and vectors

The goal of these macros are to reduce the amount of allocations that are required when concatenating string buffers and vectors; with a macro that makes it simple to achieve in practice.

Implementation Notes

  • The caller must provide a buffer for appending the slices to
  • The buffer is resized to accomodate the total length of all slices given

String Concatenation

Appends any number of string slices onto a string buffer

use concat_in_place::strcat;

let domain = "domain.com";
let endpoint = "inventory/parts";
let id = "10512";

let mut url = String::new();
let slice = strcat!(&mut url, domain "/" endpoint "/" id);
assert_eq!(slice, "domain.com/inventory/parts/10512");

Implementation Notes

Technically works with any string type that has the following methods:

  • capacity
  • len
  • push_str

Vector Concatenation

Appends any number of slices onto a vector

use concat_in_place::veccat;

let domain = b"domain.com";
let endpoint = b"inventory/parts";
let id = b"10512";

let mut url = Vec::new();
let slice = veccat!(&mut url, domain b"/" endpoint b"/" id);
assert_eq!(slice, b"domain.com/inventory/parts/10512");

Implementation Notes

Technically works with any type that has the following methods:

  • capacity
  • len
  • reserve
  • extend_from_slice

No runtime deps