{"id":13599875,"url":"https://github.com/xfbs/imstr","last_synced_at":"2026-04-08T13:31:19.154Z","repository":{"id":152425123,"uuid":"619929039","full_name":"xfbs/imstr","owner":"xfbs","description":"Immutable strings, in Rust.","archived":false,"fork":false,"pushed_at":"2024-01-28T20:20:49.000Z","size":312,"stargazers_count":248,"open_issues_count":9,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-12-13T23:41:34.577Z","etag":null,"topics":["cheap","clone","copy-on-write","cow","immutable","rust","slice","string","zero-copy"],"latest_commit_sha":null,"homepage":"https://docs.rs/imstr","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/xfbs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2023-03-27T17:34:44.000Z","updated_at":"2025-11-26T19:14:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b99cdc7-42c6-47b4-b804-6330be7c55a2","html_url":"https://github.com/xfbs/imstr","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/xfbs/imstr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfbs%2Fimstr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfbs%2Fimstr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfbs%2Fimstr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfbs%2Fimstr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xfbs","download_url":"https://codeload.github.com/xfbs/imstr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfbs%2Fimstr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31558380,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T10:21:54.569Z","status":"ssl_error","status_checked_at":"2026-04-08T10:21:38.171Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cheap","clone","copy-on-write","cow","immutable","rust","slice","string","zero-copy"],"created_at":"2024-08-01T17:01:15.078Z","updated_at":"2026-04-08T13:31:19.120Z","avatar_url":"https://github.com/xfbs.png","language":"Rust","readme":"# Immutable Strings\n\n[![crates.io](https://img.shields.io/crates/v/imstr.svg)](https://crates.io/crates/imstr)\n[![docs.rs](https://img.shields.io/docsrs/imstr)](https://docs.rs/imstr)\n\nThis crate offers a cheaply cloneable and sliceable UTF-8 string type. It is\ninspired by the [`bytes`] crate, which offers zero-copy byte slices, and the\n[`im`] crate which offers immutable copy-on-write data structures. It offers\na standard-library `String`-compatible API.\n\nInternally, the crate uses a standard library string stored in a smart pointer,\nand a range into that `String`.  This allows for cheap zero-copy cloning and\nslicing of the string. This is especially useful for parsing operations, where\na large string needs to be sliced into a lot of substrings. \n\n\u003e TL;DR: This crate offers an `ImString`\n\u003e type that acts as a `String` (in that it can be modified and used in the same\n\u003e way), an `Arc\u003cString\u003e` (in that it is cheap to clone) and an `\u0026str` (in that\n\u003e it is cheap to slice) all in one, owned type.\n\n![Diagram of ImString Internals](diagram.png)\n\nThis crate offers a safe API that ensures that every string and every string\nslice is UTF-8 encoded. It does not allow slicing of strings within UTF-8\nmultibyte sequences. It offers `try_*` functions for every operation that can\nfail to avoid panics. It also uses extensive unit testing with a full test\ncoverage to ensure that there is no unsoundness.\n\n## Features\n\n**Efficient Cloning**: The crate's architecture enables low-cost (zero-copy)\nclone and slice creation, making it ideal for parsing strings that are widely\nshared.\n\n**Efficient Slicing**: The crate's architecture enables low-cost (zero-copy)\nslice creation, making it ideal for parsing operations where one large input\nstring is slices into many smaller strings.\n\n**Copy on Write**: Despite being cheap to clone and slice, it allows for\nmutation using copy-on-write. For strings that are not shared, it has an\noptimisation to be able to mutate it in-place safely to avoid unnecessary\ncopying.\n\n**Compatibility**: The API is designed to closely resemble Rust's standard\nlibrary [`String`], facilitating smooth integration and being almost a drop-in\nreplacement. It also integrates with many popular Rust crates, such as\n[`serde`], [`peg`] and [`nom`].\n\n**Generic over Storage**: The crate is flexible in terms of how the data is\nstored.  It allows for using `Arc\u003cString\u003e` for multithreaded applications and\n`Rc\u003cString\u003e` for single-threaded use, providing adaptability to different\nstorage requirements and avoiding the need to pay for atomic operations when\nthey are not needed.\n\n**Safety**: The crate enforces that all strings and string slices are UTF-8\nencoded. Any methods that might violate this are marked as unsafe. All methods\nthat can fail have a `try_*` variant that will not panic. Use of safe functions\ncannot result in unsound behaviour.\n\n## Example\n\n```rust\nuse imstr::ImString;\n\n// Create new ImString, allocates data.\nlet mut string = ImString::from(\"Hello, World\");\n\n// Edit: happens in-place (because this is the only reference).\nstring.push_str(\"!\");\n\n// Clone: this is zero-copy.\nlet clone = string.clone();\n\n// Slice: this is zero-copy.\nlet hello = string.slice(0..5);\nassert_eq!(hello, \"Hello\");\n\n// Slice: this is zero-copy.\nlet world = string.slice(7..12);\nassert_eq!(world, \"World\");\n\n// Here we have to copy only the part that the slice refers to so it can be modified.\nlet hello = hello + \"!\";\nassert_eq!(hello, \"Hello!\");\n```\n\n## Optional Features\n\nOptional features that can be turned on using feature-flags.\n\n| Feature | Description |\n| --- | --- |\n| `serde` | Serialize and deserialize `ImString` fields as strings with the [`serde`] crate. |\n| `peg` | Use `ImString` as the data structure that is parsed with the [`peg`] crate. See [`peg-list.rs`](examples/peg-list.rs) for an example. |\n| `nom` | Allow `ImString` to be used to build parsers with [`nom`]. See [`nom-json.rs`](examples/nom-json.rs) for an example. |\n\n## Similar\n\n\u003e There are several crates similar to this, which are listed in the [Rust String\n\u003e Benchmarks](https://github.com/rosetta-rs/string-rosetta-rs). You may want\n\u003e to check the other crates out as well.\n\nThis is a comparison of this crate to other, similar crates. The comparison is\nmade on these features:\n\n- **Cheap Clone**: is it a zero-copy operation to clone a string?\n- **Cheap Slice** 🍕: is it possibly to cheaply slice a string?\n- **Mutable**: is it possible to modify strings?\n- **Generic Storage**: is it possible to swap out the storage mechanism?\n- **String Compatible**: is it compatible with [`String`]?\n\nHere is the data, with links to the crates for further examination:\n\n| Crate | Cheap Clone| Cheap Slice | Mutable | Generic Storage | String Compatible | Notes |\n| --- | --- | --- | --- | --- | --- | --- |\n| [`imstr`] | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | This crate. |\n| [`tendril`] |:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:|❌| Complex implementation. API not quite compatible with [`String`], but otherwise closest to what this crate does. |\n| [`immut_string`] |:heavy_check_mark:|❌| 🟡 (no optimization) |❌|❌| Simply a wrapper around `Arc\u003cString\u003e`. |\n| [`immutable_string`] |:heavy_check_mark:|❌|❌|❌|❌| Wrapper around `Arc\u003cstr\u003e`. |\n| [`arccstr`] |:heavy_check_mark:|❌|❌|❌|❌| Not UTF-8 (Null-terminated C string). Hand-written `Arc` implementation. |\n| [`implicit-clone`] |:heavy_check_mark:|❌|❌|🟡|:heavy_check_mark:| Immutable string library. Has `sync` and `unsync` variants. |\n| [`semistr`] |❌|❌|❌|❌|❌| Stores short strings inline. |\n| [`quetta`] |:heavy_check_mark:|:heavy_check_mark:|❌|❌|❌| Wrapper around `Arc\u003cString\u003e` that can be sliced. |\n| [`bytesstr`] |:heavy_check_mark:|🟡|❌|❌|❌| Wrapper around `Bytes`. Cannot be directly sliced. |\n| [`fast-str`] |:heavy_check_mark:|❌|❌|❌|❌| Looks like there could be some unsafety. |\n| [`flexstr`] |:heavy_check_mark:|❌|❌|:heavy_check_mark:|❌| |\n| [`bytestring`] |:heavy_check_mark:|🟡|❌|❌|❌| Wrapper around `Bytes`. Used by `actix`. Can be indirectly sliced using `slice_ref()`. |\n| [`arcstr`] |:heavy_check_mark:|:heavy_check_mark:|❌|❌|❌| Can store string literal as `\u0026'static str`. |\n| [`cowstr`] |:heavy_check_mark:|❌|:heavy_check_mark:|❌|❌| Reimplements `Arc`, custom allocation strategy. |\n| [`strck`] |❌|❌|❌|:heavy_check_mark:|❌| Typechecked string library. |\n\n## License\n\nMIT, see [LICENSE.md](LICENSE.md).\n\n[`imstr`]: https://crates.io/crates/imstr\n[`tendril`]: https://crates.io/crates/tendril\n[`immut_string`]: https://crates.io/crates/immut_string\n[`immutable_string`]: https://crates.io/crates/immutable_string\n[`arccstr`]: https://crates.io/crates/arccstr\n[`implicit-clone`]: https://crates.io/crates/implicit-clone\n[`semistr`]: https://crates.io/crates/semistr\n[`quetta`]: https://crates.io/crates/quetta\n[`bytesstr`]: https://crates.io/crates/bytesstr\n[`fast-str`]: https://crates.io/crates/fast-str\n[`flexstr`]: https://crates.io/crates/flexstr\n[`bytestring`]: https://crates.io/crates/bytestring\n[`arcstr`]: https://crates.io/crates/arcstr\n[`cowstr`]: https://crates.io/crates/cowstr\n[`strck`]: https://crates.io/crates/strck\n[`String`]: https://doc.rust-lang.org/std/string/struct.String.html\n[`bytes`]: https://crates.io/crates/bytes\n[`im`]: https://crates.io/crates/im\n[`serde`]: https://crates.io/crates/serde\n[`peg`]: https://crates.io/crates/peg\n[`nom`]: https://crates.io/crates/nom\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxfbs%2Fimstr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxfbs%2Fimstr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxfbs%2Fimstr/lists"}