#immutable #copy #rc #cheap-clone

implicit-clone

Immutable types and ImplicitClone trait similar to Copy

7 releases

Uses new Rust 2021

0.3.2 Jul 12, 2022
0.3.1 Apr 16, 2022
0.2.0 Apr 15, 2022
0.1.3 Apr 15, 2022

#223 in Rust patterns

Download history 25/week @ 2022-06-06 18/week @ 2022-06-13 295/week @ 2022-06-20 623/week @ 2022-06-27 373/week @ 2022-07-04 333/week @ 2022-07-11 748/week @ 2022-07-18 443/week @ 2022-07-25 600/week @ 2022-08-01 477/week @ 2022-08-08 394/week @ 2022-08-15 472/week @ 2022-08-22 496/week @ 2022-08-29 450/week @ 2022-09-05 674/week @ 2022-09-12 436/week @ 2022-09-19

2,172 downloads per month

MIT/Apache

30KB
638 lines

main Latest Version License Docs.rs LOC Dependency Status

ImplicitClone

A library that introduces the marker trait ImplicitClone which allows reproducing the behavior of the trait Copy but calls the Clone implementation instead and must be implemented in the host library.

The idea is that you must implement this trait on types that are cheap to clone (std::rc::Rc and std::sync::Arc types are automatically implemented). Then the host library must use the trait ImplicitClone to allow their users to pass objects that will be cloned automatically.

This crate is in the category rust-patterns but this is actually a Rust anti-pattern. In Rust the user should always handle borrowing and ownership by themselves. Nevertheless, this pattern is sometimes desirable. For example, UI frameworks that rely on propagating properties from ancestors to children will always need to use Rc'ed types to allow every child component to update. This is the case in React-like framework like Yew.

This crates also provide a few convenient immutable types for handling cheap-to-clone string, array and maps which you can find in the modules sync and unsync. Those types implement ImplicitClone and hold only types that implement ImplicitClone as well. One big particularity: iterating on these types yields clones of the items and not references. This can be particularly handy when using a React-like framework.

Dependencies

~100KB