-
-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: publish
Oco
separately as oco_ref
crate so that it can be …
…used elsewhere (#2536)
- Loading branch information
Showing
7 changed files
with
136 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "oco_ref" | ||
edition = "2021" | ||
version = "0.1.1" | ||
authors = ["Danik Vitek", "Greg Johnston"] | ||
license = "MIT" | ||
repository = "https://github.com/leptos-rs/leptos" | ||
description = "A smart pointer for storing immutable values with relatively-cheap cloning. (Like a `Cow` meets an `Rc`!)" | ||
rust-version.workspace = true | ||
|
||
[dependencies] | ||
serde = "1" | ||
thiserror = "1" | ||
|
||
[dev-dependencies] | ||
serde_json = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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. | ||
|
||
```rust | ||
use oco_ref::Oco; | ||
use std::rc::Rc; | ||
|
||
let static_str = "foo"; | ||
let rc_str: Rc<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(rc_str); | ||
uses_oco(owned_str); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters