{"id":29510895,"url":"https://github.com/vigna/value-traits-rs","last_synced_at":"2026-03-13T16:33:55.989Z","repository":{"id":290546349,"uuid":"973038971","full_name":"vigna/value-traits-rs","owner":"vigna","description":"Value-based analogues of standard Rust traits","archived":false,"fork":false,"pushed_at":"2026-02-15T16:40:26.000Z","size":203,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-15T23:32:01.951Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vigna.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-Apache-2.0","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-04-26T05:58:18.000Z","updated_at":"2026-02-15T16:39:09.000Z","dependencies_parsed_at":"2025-10-15T22:41:12.681Z","dependency_job_id":"fbfc5ca3-94c3-44f4-82fd-7a468cd74819","html_url":"https://github.com/vigna/value-traits-rs","commit_stats":null,"previous_names":["vigna/value-traits-rs"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/vigna/value-traits-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vigna%2Fvalue-traits-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vigna%2Fvalue-traits-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vigna%2Fvalue-traits-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vigna%2Fvalue-traits-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vigna","download_url":"https://codeload.github.com/vigna/value-traits-rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vigna%2Fvalue-traits-rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30471103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T11:00:43.441Z","status":"ssl_error","status_checked_at":"2026-03-13T11:00:23.173Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":[],"created_at":"2025-07-16T09:43:31.593Z","updated_at":"2026-03-13T16:33:55.977Z","avatar_url":"https://github.com/vigna.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Traits By Value\n\n[![downloads](https://img.shields.io/crates/d/value-traits)](https://crates.io/crates/value-traits)\n[![dependents](https://img.shields.io/librariesio/dependents/cargo/value-traits)](https://crates.io/crates/value-traits/reverse_dependencies)\n![GitHub CI](https://github.com/vigna/value-traits-rs/actions/workflows/rust.yml/badge.svg)\n![license](https://img.shields.io/crates/l/value-traits)\n[![Latest version](https://img.shields.io/crates/v/value-traits.svg)](https://crates.io/crates/value-traits)\n[![Documentation](https://docs.rs/value-traits/badge.svg)](https://docs.rs/value-traits)\n[![Coverage Status](https://coveralls.io/repos/github/vigna/value-traits-rs/badge.svg?branch=main)](https://coveralls.io/github/vigna/value-traits-rs?branch=main)\n\n## Why\n\nSlices are one of the most pervasive types in Rust—and with good reasons. They\nare lightweight, flexible, and represent a basic data structure, the _sequence_,\nAKA _random-access list_.\n\nThe problem with slices is that, by design, they are accessed by _reference_:\nthe most used slice trait, [`Index`], gives a reference to an element of the\nslice. While this approach is elegant and makes several compiler optimizations\npossible, it also means that slices cannot be used as generic random-access\nlists, as access by reference means there must be an actual contiguous segment\nof memory locations containing explicit representations\nof the elements of the lists. However, there are also different list\nrepresentations, such as compressed, succinct, functional, implicit, and so on.\n\nFor this reason, this crate provides traits parallel to slices and iterators,\nbut by value, rather than by reference. [`SliceByValue`] specifies the type of\nvalues of the slice (via an associated type), its length, ad provides methods\nthat are exactly analogous of [`std::slice::get`] and [`Index::index`], but\nreturn values, rather than references; they are named [`get_value`] and\n[`index_value`] instead. The longer names are necessary to avoid ambiguity, as\nall slices of cloneable elements implement our by-value traits. It might be\nargued `RandomAccessList` or `Sequence` might be more standard name, but we want\nto underline the fact that the read access is closely modeled after slices. Note\nthat we cannot overload the `[]` operator, as [`Index`] methods must necessarily\nreturn references.\n\nWrite access is a different issue because [`SliceByValueMut`] has necessarily a\ncompletely different setup than [`IndexMut::index_mut`]. It provides ways\nto [set], [replace], or even [apply a function to an element of the slice], plus\na [few convenience methods]. All methods except for the set methods have\ndefault implementations.\n\nFinally, like slices, slices by value can provide [subslicing]. Subslicing\ntraits are distinct traits, as you might be contented, for your application, of\n(possibly read-only) access to single elements. Similarly to the access to\nsingle elements, you have methods such as [`get_subslice`] and\n[`index_subslice`], which have the same semantics as the corresponding methods\nof slices.\n\nThe other missing trait contained in this crate is [`IterateByValue`], which has\nthe same logic for iterators. Rust has presently no trait specifying that you\ncan iterate by value on some structure without consuming it as [`IntoIterator`]\ndoes. What one usually does is to implement [`IntoIterator`] on a reference,\nproviding an iterator on references on the elements, which brings back the\nproblem of constraining such implementations to explicit representations. While\nit is possible to implement [`IntoIterator`] in such a way to return values,\nmany standard types as slices, vectors, etc., already have implementations\nreturning references, so a different trait is necessary.\n\nImplementing subslices is tricky, so [`Subslices`] is a derive macro that\nprovides a complete implementation of subslicing for a type that implements\n[`SliceByValue`]; [`SubslicesMut`] similarly provides a complete implementation\nof subslicing for a type that implements [`SliceByValueMut`]. Note that a custom\nimplementation might be more efficient if your type can directly represent an\ninner range. Analogous derive macros [`Iterators`] and [`IteratorsMut`]\nimplement the by-value iteration traits for the structures created by\n[`Subslices`] and [`SubslicesMut`]. All these derive macros are independent to\nmake specialized, more efficient implementation possible at every step.\n\nOne important difference with slices is that iterating subslicing will lead\nto different types. We could not find any way to express in the current Rust\ntype system the recursive bound that subslices of a subslice should be of\nthe same type. This is not relevant if you pass the subslice to a function\nthat accepts a by-value slice, but it is relevant if you want to assign\nsubslices of different depth to the same variable.\n\n[`SliceByValue`]: \u003chttps://docs.rs/value_traits/latest/value_traits/slices/trait.SliceByValue.html\u003e\n[`SliceByValueMut`]: \u003chttps://docs.rs/value_traits/latest/value_traits/slices/trait.SliceByValueMut.html\u003e\n[subslicing]: \u003chttps://docs.rs/value-traits/latest/value_traits/slices/trait.SliceByValueSubslice.html\u003e\n[`get_value`]: \u003chttps://docs.rs/value_traits/latest/value_traits/slices/trait.SliceByValue.html#tymethod.get_value\u003e\n[`index_value`]: \u003chttps://docs.rs/value_traits/latest/value_traits/slices/trait.SliceByValue.html#tymethod.index_value\u003e\n[`get_subslice`]: \u003chttps://docs.rs/value_traits/latest/value_traits/slices/trait.SliceByValueSubslice.html#tymethod.get_subslice\u003e\n[`index_subslice`]: \u003chttps://docs.rs/value_traits/latest/value_traits/slices/trait.SliceByValueSubslice.html#tymethod.index_subslice\u003e\n[`IterateByValue`]: \u003chttps://docs.rs/value_traits/latest/value_traits/iter/trait.IterateByValue.html\u003e\n[`IntoIterator`]: \u003chttps://doc.rust-lang.org/std/iter/trait.IntoIterator.html\u003e\n[`std::slice::get`]: \u003chttps://doc.rust-lang.org/std/slice/trait.SliceIndex.html#tymethod.get\u003e\n[`Index::index`]: \u003chttps://doc.rust-lang.org/std/ops/trait.Index.html#tymethod.index\u003e\n[`Index`]: \u003chttps://doc.rust-lang.org/std/ops/trait.Index.html\u003e\n[`IndexMut::index_mut`]: \u003chttps://doc.rust-lang.org/std/ops/trait.IndexMut.html#tymethod.index_mut\u003e\n[`Subslices`]: \u003chttps://docs.rs/value_traits_derive/latest/value_traits_derive/derive.Subslices.html\u003e\n[`SubslicesMut`]: \u003chttps://docs.rs/value_traits_derive/latest/value_traits_derive/derive.SubslicesMut.html\u003e\n[`Iterators`]: \u003chttps://docs.rs/value_traits_derive/latest/value_traits_derive/derive.Iterators.html\u003e\n[`IteratorsMut`]: \u003chttps://docs.rs/value_traits_derive/latest/value_traits_derive/derive.IteratorsMut.html\u003e\n[set]: \u003chttps://docs.rs/value_traits/latest/value_traits/slices/trait.SliceByValueMut.html#method.set_value\u003e\n[replace]: \u003chttps://docs.rs/value_traits/latest/value_traits/slices/trait.SliceByValueMut.html#method.replace_value\u003e\n[apply a function to an element of the slice]: \u003chttps://docs.rs/value_traits/latest/value_traits/slices/trait.SliceByValueMut.html#method.apply_in_place\u003e\n[few convenience methods]: \u003chttps://docs.rs/value_traits/latest/value_traits/slices/trait.SliceByValueMut.html#method.copy\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvigna%2Fvalue-traits-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvigna%2Fvalue-traits-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvigna%2Fvalue-traits-rs/lists"}