summaryrefslogtreecommitdiff
path: root/rust/alloc/vec
diff options
context:
space:
mode:
authorMiguel Ojeda <ojeda@kernel.org>2022-12-06 04:05:19 +0300
committerMiguel Ojeda <ojeda@kernel.org>2023-01-16 23:03:49 +0300
commit8909a80e3f684fb274a171489c16e8f10c482e83 (patch)
treeaa07f495d0a8439d6a3a5fbef53587606f2ff052 /rust/alloc/vec
parent5dc4c995db9eb45f6373a956eb1f69460e69e6d4 (diff)
downloadlinux-8909a80e3f684fb274a171489c16e8f10c482e83.tar.xz
rust: alloc: remove the `borrow` module (`ToOwned`, `Cow`)
The `Cow` type [1] requires that its generic parameter type implements the `ToOwned` trait [2], which provides a method to create owned data from borrowed data, usually by cloning. However, it is infallible, and thus in most cases it is not useful for the kernel. [3] Therefore, introduce `cfg(no_borrow)` to remove the `borrow` module (which contains `ToOwned` and `Cow`) from `alloc`. Link: https://doc.rust-lang.org/alloc/borrow/enum.Cow.html [1] Link: https://doc.rust-lang.org/alloc/borrow/trait.ToOwned.html [2] Link: https://lore.kernel.org/rust-for-linux/20221204103153.117675b1@GaryWorkstation/ [3] Cc: Gary Guo <gary@garyguo.net> Cc: Wedson Almeida Filho <wedsonaf@gmail.com> Cc: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Reviewed-by: Wei Liu <wei.liu@kernel.org> Reviewed-by: Finn Behrens <fin@nyantec.com>
Diffstat (limited to 'rust/alloc/vec')
-rw-r--r--rust/alloc/vec/mod.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/rust/alloc/vec/mod.rs b/rust/alloc/vec/mod.rs
index 8ac6c1e3b2a8..f77c7368d534 100644
--- a/rust/alloc/vec/mod.rs
+++ b/rust/alloc/vec/mod.rs
@@ -72,6 +72,7 @@ use core::ptr::{self, NonNull};
use core::slice::{self, SliceIndex};
use crate::alloc::{Allocator, Global};
+#[cfg(not(no_borrow))]
use crate::borrow::{Cow, ToOwned};
use crate::boxed::Box;
use crate::collections::TryReserveError;
@@ -94,6 +95,7 @@ pub use self::drain::Drain;
mod drain;
+#[cfg(not(no_borrow))]
#[cfg(not(no_global_oom_handling))]
mod cow;
@@ -3103,6 +3105,7 @@ impl<T, const N: usize> From<[T; N]> for Vec<T> {
}
}
+#[cfg(not(no_borrow))]
#[stable(feature = "vec_from_cow_slice", since = "1.14.0")]
impl<'a, T> From<Cow<'a, [T]>> for Vec<T>
where