2
0
Fork 0
mirror of https://github.com/leptos-rs/leptos synced 2025-02-02 23:13:25 +00:00
leptos/oco
Saber Haj Rabiee d4044cd5a1
feat: add autofix.ci to address formatting issues and possible clippy fixes ()
* feat: add `autofix.ci` to address formatting issues and possible clippy
fixes

* fix: initial run of `autofix.ci` script to prevent PR pollution at first
run

* fix: typo and indent issue in `autofix.yml`

* fix: run `autofix.ci` over members with no features
2024-11-12 10:54:14 -08:00
..
src feat: add autofix.ci to address formatting issues and possible clippy fixes () 2024-11-12 10:54:14 -08:00
Cargo.toml Dependabot, Attemp () 2024-11-07 10:55:57 -08:00
Makefile.toml prep for preview release 2024-08-01 19:40:56 -04:00
README.md prep for preview release 2024-08-01 19:40:56 -04:00

This module contains the Oco (Owned Clones Once) smart pointer, which is used to store immutable references to values. This is useful for storing, for example, strings.

Imagine this as an alternative to [Cow] with an additional, reference-counted branch.

use oco_ref::Oco;
use std::sync::Arc;

let static_str = "foo";
let arc_str: Arc<str> = "bar".into();
let owned_str: String = "baz".into();

fn uses_oco(value: impl Into<Oco<'static, str>>) {
    let mut value = value.into();

    // ensures that the value is either a reference, or reference-counted
    // O(n) at worst
    let clone1 = value.clone_inplace();

    // these subsequent clones are O(1)
    let clone2 = value.clone();
    let clone3 = value.clone();
}

uses_oco(static_str);
uses_oco(arc_str);
uses_oco(owned_str);