No description
Find a file
Samuel Collins 95eb3b389e
All checks were successful
checks / fmt (push) Successful in 28s
checks / Clippy (push) Successful in 28s
checks / MSRV Build & Test (push) Successful in 32s
checks / Build & Test (push) Successful in 36s
prepare for 0.5.1 release
2026-04-19 12:38:27 +01:00
.forgejo/workflows refactor: remove container traits and put deduplicating container behind feature flag (#1) 2026-04-03 11:13:04 +01:00
examples update readme for new API 2026-04-19 12:37:45 +01:00
src refactor: remove container traits and put deduplicating container behind feature flag (#1) 2026-04-03 11:13:04 +01:00
tests improve test coverage 2026-04-16 19:02:39 +01:00
.gitignore add CI checks (#2) 2026-04-03 11:09:52 +01:00
Cargo.lock prepare for 0.5.1 release 2026-04-19 12:38:27 +01:00
Cargo.toml prepare for 0.5.1 release 2026-04-19 12:38:27 +01:00
LICENSE-APACHE package metadata and docs 2022-09-02 18:02:17 +01:00
LICENSE-MIT package metadata and docs 2022-09-02 18:02:17 +01:00
README.md update readme for new API 2026-04-19 12:37:45 +01:00

contain-rs

A crate for defining/extending lifetimes.

Examples

Simple Container

A basic fast implementation backed by Vec.

use contain::SimpleContainer;

fn append_thing<'a>(container: &'a SimpleContainer<String>, s: &str) -> &'a str {
    container.put(format!("{}thing", s))
}

fn main() {
    let container = SimpleContainer::new();
    let a = append_thing(&container, "some");
    let b = append_thing(&container, "a ");
    let c = append_thing(&container, "that ");
    assert_eq!(a, "something");
    assert_eq!(b, "a thing");
    assert_eq!(c, "that thing");
    assert_eq!(container.count(), 3);
}

Deduplicating Container

A deduplicating container backed by indexmap::IndexMap. If two equal items are stored, the second is dropped and a reference to the first is returned. Whilst more resource-intensive than SimpleContainer, it can be more memory efficient in scenarios where many items are equal and equivalent since the duplicates will be dropped.

use contain::DeduplicatingContainer;

fn append_thing<'a>(container: &'a DeduplicatingContainer<'_, String>, s: &str) -> &'a str {
    container.put(format!("{}thing", s))
}

fn main() {
    let container = DeduplicatingContainer::new();
    let a = append_thing(&container, "some");
    let b = append_thing(&container, "a ");
    let c = append_thing(&container, "some");
    assert_eq!(a, "something");
    assert_eq!(b, "a thing");
    assert_eq!(c, "something");
    assert_eq!(container.count(), 2);
}