pgat-0.3.0/.cargo_vcs_info.json0000644000000001360000000000100117670ustar { "git": { "sha1": "0fbd7708ccb34072bd5c23ee000d183b1046fc2a" }, "path_in_vcs": "" }pgat-0.3.0/.github/workflows/ci.yml000064400000000000000000000031641046102023000152760ustar 00000000000000name: ci on: push: branches: - main pull_request: jobs: lints: name: lints runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v4 - name: Install beta toolchain uses: dtolnay/rust-toolchain@beta with: components: rustfmt, clippy - name: Set up cache uses: Swatinem/rust-cache@v2 with: cache-on-failure: true - name: Run cargo fmt run: cargo fmt --all -- --check - name: Run cargo clippy run: cargo clippy --all-targets --tests -- -D warnings no_std: name: no_std runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v4 - name: Install beta toolchain for ARM uses: dtolnay/rust-toolchain@beta with: targets: armv7a-none-eabi - name: Set up cache uses: Swatinem/rust-cache@v2 with: cache-on-failure: true - name: Build binary for armv7a-none-eabi run: cargo rustc --target=armv7a-none-eabi --manifest-path=ensure_no_std/Cargo.toml tests: name: tests runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v4 - name: Install beta toolchain uses: dtolnay/rust-toolchain@beta - name: Set up cache uses: Swatinem/rust-cache@v2 with: cache-on-failure: true - name: Run cargo test #run: cargo test --all-features --no-fail-fast --locked --workspace -- --nocapture run: cargo test --all-features --no-fail-fast --workspace -- --nocapture pgat-0.3.0/.gitignore000064400000000000000000000000441046102023000125450ustar 00000000000000# Rust /target **/*.rs.bk Cargo.lockpgat-0.3.0/Cargo.lock0000644000000005720000000000100077460ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 4 [[package]] name = "doc-comment" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "pgat" version = "0.3.0" dependencies = [ "doc-comment", ] pgat-0.3.0/Cargo.toml0000644000000022130000000000100077630ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2024" name = "pgat" version = "0.3.0" authors = ["Geordon Worley "] build = false autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "Proxy GAT: Abstractions for generic proxy views with GAT to enable generic container types" documentation = "https://docs.rs/pgat/" readme = "README.md" keywords = [ "proxy", "view", "gat", "reference", "container", ] categories = [ "no-std", "computer-vision", "data-structures", ] license = "MIT" repository = "https://github.com/rust-cv/pgat" [lib] name = "pgat" path = "src/lib.rs" [dependencies.doc-comment] version = "0.3.3" pgat-0.3.0/Cargo.toml.orig000064400000000000000000000007671046102023000134600ustar 00000000000000[package] name = "pgat" version = "0.3.0" edition = "2024" authors = ["Geordon Worley "] description = "Proxy GAT: Abstractions for generic proxy views with GAT to enable generic container types" documentation = "https://docs.rs/pgat/" repository = "https://github.com/rust-cv/pgat" keywords = ["proxy", "view", "gat", "reference", "container"] categories = ["no-std", "computer-vision", "data-structures"] license = "MIT" readme = "README.md" [dependencies] doc-comment = "0.3.3" pgat-0.3.0/LICENSE000064400000000000000000000020651046102023000115670ustar 00000000000000MIT License Copyright (c) 2025 Rust Computer Vision Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pgat-0.3.0/README.md000064400000000000000000000050221046102023000120350ustar 00000000000000# pgat [![Discord][dci]][dcl] [![Crates.io][ci]][cl] [![docs.rs][di]][dl] ![LoC][lo] ![ci][bci] [ci]: https://img.shields.io/crates/v/pgat.svg [cl]: https://crates.io/crates/pgat/ [di]: https://docs.rs/pgat/badge.svg [dl]: https://docs.rs/pgat/ [lo]: https://tokei.rs/b1/github/rust-cv/pgat?category=code [dci]: https://img.shields.io/discord/550706294311485440.svg?logo=discord&colorB=7289DA [dcl]: https://discord.gg/d32jaam [bci]: https://github.com/rust-cv/pgat/workflows/ci/badge.svg Proxy GAT: Abstractions for generic proxy views with GAT to enable generic container types The purpose of this crate is to make it possible to construct containers that allow comparing internal data which may be represented entirely differently than its original form to views of that data that may exist in an entirely different form and have to be constructed from lifetimes. The specific example that forced the creation of this crate was the use of ndarray using Array2 as a storage structure for Array1 values. A container might wish to store clusters of Array2 or use a single Array2 to store a set of Array1 values, but in doing so it makes it impossible to get a reference to the underlying Array1. When inserting or adding new Array1 values, most container types need to be able to compare the underlying data in some way, and this crate provides abstractions to create unifying view types from internal and external data for comparison. Because the [`ProxyView`] type created by this crate has no associated lifetime, it makes it possible to compare data through views of the underlying data that can be created arbitrarily and with their own lifetimes. No reference type is needed. This enables abstracting downstream code over the container type and also allows abstracting containers over the intermediary view type the user wishes. A trivial implementation that allows the view to be a basic reference &T is provided as [`ReferenceProxy`]. It is recommended for container authors to use this proxy as a default type argument for the majority of users. For containers that need to use specific proxies, they can create their own proxy, such as a wrapper around ArrayView1, and then downstream users can override the defaults on containers that are permissive to match their view to yours. Users which require specific proxies for their own uses may also override them for permissive containers. Containers that use specialized storage methods might not store the owned version of the value directly, and so those are encouraged to create unique views for their type. pgat-0.3.0/src/lib.rs000064400000000000000000000062651046102023000124730ustar 00000000000000//! See the [Crates.io page](https://crates.io/crates/pgat) for the README. #![no_std] doc_comment::doctest!("../README.md"); use core::marker::PhantomData; /// A convenience type alias to get a view from a proxy and a lifetime. pub type View<'a, P> =

::View<'a>; /// A convenience type alias to get an owned value from a proxy. pub type Owned

=

::Owned; /// A type generator that produces a view type for a given lifetime. /// /// The owned value associated with the proxy is required to outlive any borrow lifetime, /// so it's type must be known when this trait is implemented. You also need to implement /// the [`ViewInverse`] trait for the view type, which allows you to obtain the proxy from the view. /// /// It also provides a static method to generate a view from a reference to an owned value, /// though views may be generated in alternative ways. The view must always be generatable /// from a reference to the owned value. An example is ndarray arrays, which can be viewed /// as sub-slices, but you can always create a view from a single owned array. For instance, /// you might store multiple Array1 using Array2 and create views using rows/columns, but /// it is important that new points being added to the space can be viewed using an ArrayView1 /// just like you can for points stored in the Array2 so that they can be compared. pub trait ProxyView { /// The concrete type that this proxy borrows from. type Owned; /// The borrowed view type for a given lifetime. /// `Self::Owned` must outlive the borrow lifetime to ensure safety. type View<'a>: ViewInverse<'a, Proxy = Self, Owned = Self::Owned> where Self::Owned: 'a; fn view<'a>(owned: &'a Self::Owned) -> Self::View<'a>; } /// This trait is implemented for all view types and allows obtaining the proxy that produces this view. /// It can be used by abstract containers to infer the proxy type from the view type to allow the user to /// directly name the view type instead of the proxy type. This is only possible because a view type always /// has a unique proxy type associated with it, which is the one that produces the view. This also means /// that the definition of these two traits mutually requires both to be defined simultaneously for any /// view and proxy pair. pub trait ViewInverse<'a>: Copy { type Owned: 'a; type Proxy: ProxyView = Self, Owned = Self::Owned>; } impl<'a, T> ViewInverse<'a> for &'a T { type Owned = T; type Proxy = ReferenceProxy; } /// Provides a generic way to clone owned values from arbitrary proxies. pub trait ProxyToOwned: ProxyView { fn to_owned_proxy<'a>(view: Self::View<'a>) -> Self::Owned; } /// A proxy that simply returns a reference to the owned value. pub struct ReferenceProxy(pub PhantomData); impl ReferenceProxy { pub fn new() -> Self { ReferenceProxy(PhantomData) } } impl Default for ReferenceProxy { fn default() -> Self { Self::new() } } impl ProxyView for ReferenceProxy { type Owned = T; type View<'a> = &'a T where Self::Owned: 'a; fn view<'a>(owned: &'a Self::Owned) -> Self::View<'a> { owned } }