{"id":34503832,"url":"https://github.com/nberlette/moos","last_synced_at":"2026-03-17T16:38:33.128Z","repository":{"id":327952553,"uuid":"1094791751","full_name":"nberlette/moos","owner":"nberlette","description":"Memory-Optimized Objects \u0026 Strings for Rust. Includes stack-allocated inline string constructs and a memory-efficient String-only alternative to std::borrow::Cow. #no_std","archived":false,"fork":false,"pushed_at":"2026-01-02T05:57:42.000Z","size":68,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-15T17:53:06.013Z","etag":null,"topics":["allocation","copy-on-write","cow","memory","no-std","optimization","rust","short-string","stack-based"],"latest_commit_sha":null,"homepage":"","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/nberlette.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"ko_fi":"nberlette"}},"created_at":"2025-11-12T07:12:10.000Z","updated_at":"2026-01-05T16:21:18.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/nberlette/moos","commit_stats":null,"previous_names":["nberlette/moos"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/nberlette/moos","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nberlette%2Fmoos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nberlette%2Fmoos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nberlette%2Fmoos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nberlette%2Fmoos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nberlette","download_url":"https://codeload.github.com/nberlette/moos/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nberlette%2Fmoos/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30627233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T14:16:03.965Z","status":"ssl_error","status_checked_at":"2026-03-17T14:16:03.380Z","response_time":56,"last_error":"SSL_read: 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":["allocation","copy-on-write","cow","memory","no-std","optimization","rust","short-string","stack-based"],"created_at":"2025-12-24T02:39:10.814Z","updated_at":"2026-03-17T16:38:33.122Z","avatar_url":"https://github.com/nberlette.png","language":"Rust","funding_links":["https://ko-fi.com/nberlette"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# [moos]\n\n##### \u003cu\u003eM\u003c/u\u003eemory-\u003cu\u003eO\u003c/u\u003eptimized \u003cu\u003eO\u003c/u\u003ebjects and \u003cu\u003eS\u003c/u\u003etrings \u003csup\u003e_(`no_std`)_\u003c/sup\u003e\n\n\u003c/div\u003e\n\n---\n\n## Overview\n\n**`moos`** — pronounced _\"moose\"_ — is a small collection of memory-optimized\nstring types for Rust, implementing small string optimization (SSO) techniques\nand copy-on-write (COW) semantics to minimize heap allocations and improve the\nperformance of string operations.\n\nDesigned for use in `no_std` environments, `moos` prioritizes performance,\nmemory efficiency, and interoperability with common Rust string types. It is\nideal for applications where memory usage is a concern, such as embedded systems\nor real-time applications.\n\n## Usage\n\n```sh\ncargo add moos\n```\n\n```toml\n[dependencies]\n  moos = \"0.1\"\n```\n\n---\n\n## `CowStr\u003c'a\u003e`\n\nMemory-optimized alternative to `Cow\u003c'a, str\u003e`. It supports a special\n[`CowStr::Inlined`](#cowstrinlined) variant — in addition to\n[`CowStr::Owned`](#cowstrowned) and [`CowStr::Borrowed`](#cowstrborrowed), like\nits `std::borrow` counterpart — which allows\n[small strings](#max_inline_str_len) to be stored inline on the stack, reducing\nheap allocations and improving performance for small string operations common in\nmany applications.\n\n### Variants\n\n#### `CowStr::Owned`\n\nRepresents an owned string that is always heap-allocated.\n\n```rust\nuse moos::CowStr;\n\nlet owned_str = CowStr::Owned(box \"Owned string data.\");\n\nassert!(owned_str.is_owned());\n```\n\n#### `CowStr::Borrowed`\n\nRepresents a borrowed string slice (`\u0026str`) that is stored on the stack.\n\n```rust\nuse moos::CowStr;\n\nlet borrowed_str = CowStr::Borrowed(\"This is a borrowed \u0026str.\");\n\nassert!(borrowed_str.is_borrowed());\n```\n\n#### `CowStr::Inlined`\n\nRepresents a small string that is stored inline on the stack. This variant is\nused for strings that are shorter than or equal to [`MAX_INLINE_STR_LEN`].\n\n```rust\nuse moos::CowStr;\n\nlet inlined_str = CowStr::Inlined(\"Inlined string\".into());\n\nassert!(inlined_str.is_inlined());\n```\n\n### Example\n\n```rust\nuse moos::CowStr;\n\n// `CowStr::Owned` variant - always heap-allocated\nlet owned_str = CowStr::from(String::from(\"Owned string data.\"));\n\n// `CowStr::Inlined` variant - stored on the stack\nlet small_str = CowStr::from(\"Hello, world!\"); // Stored inline on x64\n\n// `CowStr::Borrowed` variant - stored on the stack\nlet large_str = CowStr::from(\"This string exceeds the inline limit.\");\n\nassert!(owned_str.is_owned());\nassert!(small_str.is_inlined());\nassert!(large_str.is_borrowed());\n```\n\n---\n\n## `InlineStr`\n\nThe `InlineStr` type is a fixed-size string type that can store small strings\ndirectly on the stack, up to a maximum length defined by [`MAX_INLINE_STR_LEN`].\n\nThis allows for efficient storage and manipulation of small strings without heap\nallocations, making it ideal for performance-critical applications where memory\nusage is a concern, such as embedded systems or real-time applications.\n\n- [x] Supports UTF-8 encoded strings.\n- [x] Provides conversion methods to and from standard string types.\n- [x] Implements common traits like `Deref`, `AsRef\u003cstr\u003e`, `Display`, `Debug`\n- [x] Supports comparison and ordering operations.\n- [x] Supports serialization/deserialization with **[serde]**\n  \u003e **Note**: Requires the `serde` feature flag to be enabled.\n\n```rust\nuse moos::InlineStr;\n\n// Create an InlineStr from a string slice\nlet inline_str = InlineStr::try_from(\"Hello, InlineStr!\").unwrap();\n// Implements the Display trait for easy printing\nprintln!(\"InlineStr content: {inline_str}\");\n\n// Can be compared with regular strings and slices\nassert_eq!(inline_str, \"Hello, InlineStr!\");\n\n// Supports mutation of the underlying byte buffer\nlet mut mutable_inline_str = inline_str;\nmutable_inline_str.as_bytes_mut()[7..14].copy_from_slice(b\"World!!\");\nprintln!(\"Modified InlineStr content: {mutable_inline_str}\");\n```\n\nAttempting to create an InlineStr from a string that is too long:\n\n```rust\nlet long_string = \"This string is longer than the max length for InlineStr.\";\nmatch InlineStr::try_from(long_string) {\n  Ok(inline_str) =\u003e println!(\"Successfully created InlineStr: {inline_str}\"),\n  Err(e) =\u003e println!(\"Error creating InlineStr: {e}\"),\n}\n```\n\n### `MAX_INLINE_STR_LEN`\n\nThe constant `MAX_INLINE_STR_LEN` defines the maximum length of an inline string\nin bytes, determined by the target architecture's pointer width. On 64-bit\nsystems, this is typically 22 B, while on 32-bit systems, it's usually 10 B.\n\n\u003e This value is calculated as 3 times the size of an `isize` (to account for\n\u003e UTF-8 encoding), minus 2 bytes to reserve space for a `u8` length byte and a\n\u003e null terminator (`\\0`) character (not stored but conceptually present in a\n\u003e manner similar to C-style strings).\n\n### `StringTooLongError`\n\nThe `StringTooLongError` is an error type returned when attempting to create an\n`InlineStr` from a string or string slice (`\u0026str`) that exceeds the maximum\nallowed length defined by [`MAX_INLINE_STR_LEN`].\n\n```rust\nuse moos::inline_str::{InlineStr, StringTooLongError};\n\n// Attempt to create an InlineStr from a string that is too long\nlet long_string = \"This string is longer than the max length for InlineStr.\";\n\nmatch InlineStr::try_from(long_string) {\n  Ok(inline_str) =\u003e println!(\"Successfully created InlineStr: {inline_str}\"),\n  Err(e) =\u003e println!(\"Error creating InlineStr: {e}\"),\n}\n```\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\n**[MIT] © [Nicholas Berlette].** All rights reserved.\n\n\u003csmall\u003e\n\n[moos] · [github] · [issues] · [docs] · [contributing]\n\n\u003c/small\u003e\u003c/div\u003e\n\n[MIT]: https://nick.mit-license.org/2025 \"MIT © Nicholas Berlette. All rights reserved.\"\n[Nicholas Berlette]: https://github.com/nberlette \"Follow @nberlette on GitHub for more cool stuff!\"\n[`MAX_INLINE_STR_LEN`]: #max_inline_str_len\n[serde]: https://crates.io/crates/serde \"Serialization framework for Rust\"\n[moos]: https://crates.io/crates/moos \"moos on crates.io\"\n[GitHub]: https://github.com/nberlette/moos \"moos on GitHub\"\n[Issues]: https://github.com/nberlette/moos/issues \"moos issues on GitHub\"\n[Docs]: https://docs.rs/moos \"moos documentation on docs.rs\"\n[Contributing]: https://github.com/nberlette/moos/blob/main/.github/CONTRIBUTING.md \"Contributing to moos on GitHub\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnberlette%2Fmoos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnberlette%2Fmoos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnberlette%2Fmoos/lists"}