prep for preview release

This commit is contained in:
Greg Johnston
2024-04-27 11:04:23 -04:00
parent 81fc7e6ada
commit 0beef3b2e0
30 changed files with 146 additions and 195 deletions

View File

@@ -1,7 +1,8 @@
[package]
name = "oco_ref"
name = "oco_ref"
edition = "2021"
version = "0.1.1"
version = "0.2.0"
authors = ["Danik Vitek", "Greg Johnston"]
license = "MIT"
repository = "https://github.com/leptos-rs/leptos"

1
oco/Makefile.toml Normal file
View File

@@ -0,0 +1 @@
extend = { path = "../cargo-make/main.toml" }

View File

@@ -1,31 +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.
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.
Imagine this as an alternative to [`Cow`] with an additional, reference-counted
branch.
```rust
use oco_ref::Oco;
use std::rc::Rc;
```rust
use oco_ref::Oco;
use std::sync::Arc;
let static_str = "foo";
let rc_str: Rc<str> = "bar".into();
let owned_str: String = "baz".into();
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();
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();
// 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();
}
// 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);
```
uses_oco(static_str);
uses_oco(arc_str);
uses_oco(owned_str);
```

View File

@@ -272,24 +272,6 @@ where
}
}
}
/// Converts the value into its cheaply-clonable form in place.
/// In other words, if it is currently [`Oco::Owned`], converts into [`Oco::Counted`]
/// in an `O(n)` operation, so that all future clones are `O(1)`.
///
/// # Examples
/// ```
/// # use leptos_reactive::oco::Oco;
/// let mut oco = Oco::<str>::Owned("Hello".to_string());
/// oco.upgrade_inplace();
/// assert!(oco1.is_counted());
/// ```
pub fn upgrade_inplace(&mut self) {
if let Self::Owned(v) = &*self {
let rc = Arc::from(v.borrow());
*self = Self::Counted(rc);
}
}
}
impl<T: ?Sized> Default for Oco<'_, T>