rep-str 0.1.0

A crate for caching a repeat pattern of a str.
Documentation
  • Coverage
  • 57.14%
    4 out of 7 items documented1 out of 7 items with examples
  • Size
  • Source code size: 38.84 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.28 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Neutron3529

This is a crate for caching a repeat pattern of a str with only one allocation by generate a new RepStr struct this crate provides.

Example 1: Crate RepStr directly.

use rep_str::RepStr;
let repstr = rep_str::RepStr::new("#", 50); // generate a RepStr object with max repeat time 50
assert!("##########" == repstr.repeat_unwrap(10));
assert!("####################" == repstr.repeat_unwrap(20));
// no extra allocation would occurs:
assert!(repstr.repeat_unwrap(20).as_ptr() == repstr.repeat(12).unwrap().as_ptr())
// repstr.repeat_unwrap(51) // panic!

Example 2: Crate RepStr by IntoRepStr trait

use rep_str::IntoRepStr;
let repstr = "🦀".repeat_cache(20);
assert!(Some("🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀") == repstr.repeat(20));
assert!(None == repstr.repeat(21));