| Crates.io | polymorph |
| lib.rs | polymorph |
| version | 1.0.0 |
| created_at | 2021-10-28 17:13:59.898367+00 |
| updated_at | 2026-01-23 07:17:40.67868+00 |
| description | A few utilities to better enable polymorphic behavior in Rust. |
| homepage | https://github.com/A248/polymorph-rs |
| repository | https://github.com/A248/polymorph-rs |
| max_upload_size | |
| id | 473635 |
| size | 47,464 |
A set of utilities to better enable polymorphic behavior in Rust.
RefOrOwned<T> is an enum over borrowed and owned data. It's similar to std::borrow::Cow. However, while Cow has a ToOwned requirement, RefOrOwned does not.
RefMutOrOwned version, for when you need &mut T.into_owned is available where T: Clone.From<&T> and From<T>, as well as Deref to TRefOrBox<T> is an enum over borrowed and boxed data, i.e. &T and Box<T>. It's intended for cases where T is unsized, like when T is a trait object.
RefMutOrBox is a version of RefOrBox which uses &mut T and can be dereferenced to a mutable value.From<&T> and From<T>, as well as Deref to T.T: DynClone, an into_owned method will be made available. More on this later.Add this library to your Cargo.toml:
[dependencies]
polymorph = "1.0"
To enable interoperability with the dyn-clone trait, turn on this feature.
[dependencies]
polymorph = { version = "1.0", features = ["trait-clone"]}
This will add a RefOrBox::into_owned method which returns a Box<T>, either by returning the owned box or cloning a borrowed value.
Polymorph is well-combined with the dyn-clone and enum-dispatch crates for flexible and effective dynamic programming.
Licensed under the Apache License v2.0. See the LICENSE.txt.