{"id":15031573,"url":"https://github.com/rreverser/cow-utils-rs","last_synced_at":"2025-04-12T20:43:36.343Z","repository":{"id":60775508,"uuid":"240930291","full_name":"RReverser/cow-utils-rs","owner":"RReverser","description":"Copy-on-write string utilities for Rust","archived":false,"fork":false,"pushed_at":"2024-04-11T18:34:59.000Z","size":16,"stargazers_count":158,"open_issues_count":3,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T22:30:30.202Z","etag":null,"topics":["copy-on-write","rust","rust-lang","rustlang","strings","strings-manipulation"],"latest_commit_sha":null,"homepage":"https://docs.rs/cow-utils/latest/cow_utils/trait.CowUtils.html","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RReverser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-16T17:02:59.000Z","updated_at":"2024-09-16T06:43:37.000Z","dependencies_parsed_at":"2024-06-19T04:10:25.945Z","dependency_job_id":"38fe0ced-a02e-4b6d-a623-bfd43e874a10","html_url":"https://github.com/RReverser/cow-utils-rs","commit_stats":{"total_commits":17,"total_committers":3,"mean_commits":5.666666666666667,"dds":"0.11764705882352944","last_synced_commit":"7a6709e4e53b50566ac3d8f6252e340b58ad6a76"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fcow-utils-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fcow-utils-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fcow-utils-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fcow-utils-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RReverser","download_url":"https://codeload.github.com/RReverser/cow-utils-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631676,"owners_count":21136555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["copy-on-write","rust","rust-lang","rustlang","strings","strings-manipulation"],"created_at":"2024-09-24T20:16:04.911Z","updated_at":"2025-04-12T20:43:36.295Z","avatar_url":"https://github.com/RReverser.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Copy-on-write string utils for Rust\n\n[![Crate docs](https://img.shields.io/crates/v/cow-utils)](https://docs.rs/cow-utils/latest/cow_utils/trait.CowUtils.html)\n[![License](https://img.shields.io/github/license/RReverser/cow-utils-rs)](LICENSE)\n\nSome [`str`](https://doc.rust-lang.org/std/primitive.str.html) methods\nperform destructive transformations and so they allocate, copy into and\nreturn a new\n[`String`](https://doc.rust-lang.org/std/string/struct.String.html) even\nwhen no modification is necessary.\n\nThis crate provides a helper trait `CowUtils` with drop-in variants of\nsuch methods, which behave in the same way, but avoid extra copies and\nallocations when no modification is necessary.\n\nFor now it's only implemented for `\u0026str` and returns\n[`std::borrow::Cow\u003cstr\u003e`](https://doc.rust-lang.org/std/borrow/enum.Cow.html),\nbut in the future might be extended to other types where even more\nefficient handling is possible (e.g. in-place modifications on mutable\nstrings).\n\n## Performance\n\nThe primary motivation for this crate was ability to perform zero-alloc replacements when no match is found, so showing results only for `.replace` vs `.cow_replace` for now.\n\nThe actual results will vary depending on the inputs, but here is a taster based on `\"a\".repeat(40)` as an input and various modes (nothing matched, everything matched and replaced, everything matched from the start and deleted):\n\n| params     | .replace (ns) | .cow_replace (ns) | difference (%) |\n|------------|---------------|-------------------|----------------|\n| (\"a\", \"\")  | 408.59        | 290.27            | -29            |\n| (\"b\", \"c\") | 98.78         | 54.00             | -45            |\n| (\"a\", \"b\") | 985.99        | 1,000.70          | +1             |\n\n## Usage\n\nFirst, you need to import `CowUtils` into the scope:\n\n```rust\nuse cow_utils::CowUtils;\n```\n\nThen you can start invoking following `.cow_`-prefixed methods on\nstrings instead of the regular ones:\n\n- `.cow_replace` instead of [`str::replace`](https://doc.rust-lang.org/std/primitive.str.html#method.replace)\n- `.cow_replacen` instead of [`str::replacen`](https://doc.rust-lang.org/std/primitive.str.html#method.replacen)\n- `.cow_to_ascii_lowercase` instead of [`str::to_ascii_lowercase`](https://doc.rust-lang.org/std/primitive.str.html#method.to_ascii_lowercase)\n- `.cow_to_ascii_uppercase` instead of [`str::to_ascii_uppercase`](https://doc.rust-lang.org/std/primitive.str.html#method.to_ascii_uppercase)\n- `.cow_to_lowercase` instead of [`str::to_lowercase`](https://doc.rust-lang.org/std/primitive.str.html#method.to_lowercase)\n- `.cow_to_uppercase` instead of [`str::to_uppercase`](https://doc.rust-lang.org/std/primitive.str.html#method.to_uppercase)\n\nCheck out [the docs](https://docs.rs/cow-utils/latest/cow_utils/trait.CowUtils.html) for detailed examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frreverser%2Fcow-utils-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frreverser%2Fcow-utils-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frreverser%2Fcow-utils-rs/lists"}