{"id":24084142,"url":"https://github.com/tos-kamiya/clip_slice","last_synced_at":"2026-06-09T13:31:37.223Z","repository":{"id":142947815,"uuid":"424328307","full_name":"tos-kamiya/clip_slice","owner":"tos-kamiya","description":"clip_slice is a utility inspired by Python's slice, which allows you to specify an index backward from the end by a negative value. It is currently a proof of concept. If you need to publish it on crates.io, please request me so.","archived":false,"fork":false,"pushed_at":"2021-11-03T21:02:36.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-27T01:53:41.311Z","etag":null,"topics":["library"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tos-kamiya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-11-03T17:56:31.000Z","updated_at":"2021-11-03T21:02:39.000Z","dependencies_parsed_at":"2023-07-29T06:15:12.264Z","dependency_job_id":null,"html_url":"https://github.com/tos-kamiya/clip_slice","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tos-kamiya/clip_slice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tos-kamiya%2Fclip_slice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tos-kamiya%2Fclip_slice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tos-kamiya%2Fclip_slice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tos-kamiya%2Fclip_slice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tos-kamiya","download_url":"https://codeload.github.com/tos-kamiya/clip_slice/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tos-kamiya%2Fclip_slice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34110011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["library"],"created_at":"2025-01-10T00:19:33.713Z","updated_at":"2026-06-09T13:31:37.218Z","avatar_url":"https://github.com/tos-kamiya.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clip_slice\n\nclip_slice is a utility inspired by Python's slice, which allows you to specify an index backward from the end by a negative value.\n\n## Usage\n\n`Clip::by(\u003cslice\u003e, \u003cstart\u003e..\u003cend\u003e) -\u003e \u003cslice\u003e`  \n`Clip::mut_by(\u003cmut_slice\u003e, \u003cstart\u003e..\u003cend\u003e) -\u003e \u003cmut_slice\u003e`  \n\nHere, `\u003cstart\u003e` and `\u003cend\u003e` are indices, and if they are negative, the position is interpreted as going backward from the back end of the slice.\n\n## Examples\n\n```rust\nuse clip_slice::{Clip, ClipAsSlice, ClipSlice};\n\nfn main() {\n    // generating slices with negative indices.\n    let a = [0, 1, 2, 3, 4, 5];\n    assert_eq!(Clip::by(\u0026a[..], ..-2), \u0026[0, 1, 2, 3]);\n    assert_eq!(Clip::by(\u0026a[..], -4..-1), \u0026[2, 3, 4]);\n\n    // use in combination with rev and step_by\n    let a = [0, 1, 2, 3, 4, 5];\n    assert_eq!(\n        (\u0026a[..]).iter().rev().map(|\u0026n| n).collect::\u003cVec\u003cisize\u003e\u003e(),\n        vec![5, 4, 3, 2, 1, 0]\n    ); // normal slice \u0026 rev\n    macro_rules! ref_iter_to_vec {\n        ( $e:expr ; $t:ty ) =\u003e {\n            $e.map(|\u0026n| n).collect::\u003cVec\u003c$t\u003e\u003e()\n        };\n    }\n    assert_eq!(\n        ref_iter_to_vec!((\u0026a[..]).iter().rev(); isize),\n        vec![5, 4, 3, 2, 1, 0]\n    ); // normal slice \u0026 rev, shortened with a macro\n\n    assert_eq!(\n        ref_iter_to_vec!(Clip::by(\u0026a[..], ..-2).iter().rev(); isize),\n        vec![3, 2, 1, 0]\n    ); // clipped slice \u0026 rev\n    assert_eq!(\n        ref_iter_to_vec!(Clip::by(\u0026a[..], ..-2).iter().rev().step_by(2); isize),\n        vec![3, 1]\n    ); // clipped slice \u0026 rev/step_by\n\n    // generating mutable slices\n    let mut a = [0, 1, 2, 3, 4, 5];\n    let s = Clip::mut_by(\u0026mut a[..], 1..-2);\n    s[0] = 10;\n    assert_eq!(a, [0, 10, 2, 3, 4, 5]);\n\n    // accessing items with negative indices\n    let a = [0, 1, 2, 3, 4, 5];\n    assert_eq!(Clip::by(\u0026a[..], -1..)[0], 5);\n    assert_eq!(Clip::by(\u0026a[..], -2..)[0], 4);\n    macro_rules! at {\n        ( $slice:expr , $index:expr ) =\u003e {\n            Clip::by(\u0026$slice[..], $index..)[0]\n        };\n    }\n    assert_eq!(at!(a, -1), 5); // shortened with a macro\n    assert_eq!(at!(a, -2), 4);\n\n    // assign items with negative index\n    // let mut a = [0, 1, 2, 3, 4, 5];\n    // a[5] = 50;\n    // assert_eq!(a, [0, 1, 2, 3, 4, 50]);\n\n    macro_rules! mut_ref_at {\n        ( $slice:expr , $index:expr ) =\u003e {\n            \u0026mut Clip::mut_by(\u0026mut $slice[..], $index..)[0]\n        };\n    }\n    let mut a = [0, 1, 2, 3, 4, 5];\n    *mut_ref_at!(a, -1) = 50;\n    assert_eq!(a, [0, 1, 2, 3, 4, 50]);\n\n    let mut v = vec![0, 1, 2, 3, 4, 5];\n    *mut_ref_at!(v, -2) = 40;\n    assert_eq!(v, vec![0, 1, 2, 3, 40, 5]);\n\n    // generating slices from vectors\n    let v = vec![0, 1, 2, 3, 4, 5];\n    assert_eq!(Clip::by_as_slice(\u0026v, ..-2), \u0026[0, 1, 2, 3]);\n\n    let mut v = vec![0, 1, 2, 3, 4, 5];\n    let s = Clip::by_as_mut_slice(\u0026mut v, 1..-2);\n    s[0] = 10;\n    assert_eq!(v, vec![0, 10, 2, 3, 4, 5]);\n}\n```\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0\n   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license\n   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n\n## Similar projects\n\n* [slyce](https://github.com/mkmik/slyce/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftos-kamiya%2Fclip_slice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftos-kamiya%2Fclip_slice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftos-kamiya%2Fclip_slice/lists"}