Lines Matching defs:Cow
3494 use std::borrow::Cow;
5207 match (Cow::from(owned.clone()), Cow::from(borrowed)) {
5208 (Cow::Owned(o), Cow::Borrowed(b)) => assert!(o == owned && b == borrowed),
5209 _ => panic!("invalid `Cow::from`"),
5615 use std::borrow::Cow;
5628 fn into_cow(self) -> Cow<'a, B>;
5632 fn into_cow(self) -> Cow<'a, str> {
5633 Cow::Owned(self)
5638 fn into_cow(self) -> Cow<'a, str> {
5639 Cow::Borrowed(self)
5651 assert_eq!(String::from(Cow::Borrowed("string")), "string");
5652 assert_eq!(String::from(Cow::Owned(String::from("string"))), "string");
5681 let ys: Cow<'_, str> = "hello".into_cow();
5685 let ys: Cow<'_, str> = "ศไทย中华Việt Nam".into_cow();
6470 use std::borrow::{Cow, ToOwned};
6478 let borrowed = <$ty>::from(Cow::Borrowed($value));
6479 let owned = <$ty>::from(Cow::Owned($value.to_owned()));
6520 // test that the methods of `Cow` are usable in a const context
6522 const COW: Cow<'_, str> = Cow::Borrowed("moo");
6530 use std::borrow::Cow;
7631 match (Cow::from(owned.clone()), Cow::from(borrowed)) {
7632 (Cow::Owned(o), Cow::Borrowed(b)) => assert!(o == owned && b == borrowed),
7633 _ => panic!("invalid `Cow::from`"),
7641 assert_eq!(Vec::from(Cow::Borrowed(borrowed)), vec!["borrowed", "(slice)"]);
7642 assert_eq!(Vec::from(Cow::Owned(owned)), vec!["owned", "(vec)"]);
8910 use std::borrow::Cow;
8912 // check that Cow<'a, str> implements addition
8915 let borrowed1 = Cow::Borrowed("Hello, ");
8916 let borrowed2 = Cow::Borrowed("World!");
8917 let borrow_empty = Cow::Borrowed("");
8919 let owned1: Cow<'_, str> = Cow::Owned(String::from("Hi, "));
8920 let owned2: Cow<'_, str> = Cow::Owned(String::from("Rustaceans!"));
8921 let owned_empty: Cow<'_, str> = Cow::Owned(String::new());
8929 if let Cow::Owned(_) = borrowed1.clone() + borrow_empty.clone() {
8932 if let Cow::Owned(_) = borrow_empty.clone() + borrowed1.clone() {
8935 if let Cow::Owned(_) = borrowed1.clone() + owned_empty.clone() {
8938 if let Cow::Owned(_) = owned_empty.clone() + borrowed1.clone() {
8945 let borrowed = Cow::Borrowed("Hello, ");
8946 let borrow_empty = Cow::Borrowed("");
8948 let owned: Cow<'_, str> = Cow::Owned(String::from("Hi, "));
8949 let owned_empty: Cow<'_, str> = Cow::Owned(String::new());
8955 if let Cow::Owned(_) = borrowed.clone() + "" {
8958 if let Cow::Owned(_) = borrow_empty.clone() + "Hello, " {
8961 if let Cow::Owned(_) = owned_empty.clone() + "Hello, " {
8968 let mut borrowed1 = Cow::Borrowed("Hello, ");
8969 let borrowed2 = Cow::Borrowed("World!");
8970 let borrow_empty = Cow::Borrowed("");
8972 let mut owned1: Cow<'_, str> = Cow::Owned(String::from("Hi, "));
8973 let owned2: Cow<'_, str> = Cow::Owned(String::from("Rustaceans!"));
8974 let owned_empty: Cow<'_, str> = Cow::Owned(String::new());
8979 if let Cow::Owned(_) = s {
8985 if let Cow::Owned(_) = s {
8991 if let Cow::Owned(_) = s {
8997 if let Cow::Owned(_) = s {
9010 let mut borrowed = Cow::Borrowed("Hello, ");
9011 let borrow_empty = Cow::Borrowed("");
9013 let mut owned: Cow<'_, str> = Cow::Owned(String::from("Hi, "));
9014 let owned_empty: Cow<'_, str> = Cow::Owned(String::new());
9019 if let Cow::Owned(_) = s {
9025 if let Cow::Owned(_) = s {
9031 if let Cow::Owned(_) = s {
9044 let mut c1: Cow<'_, str> = Cow::Owned(String::with_capacity(25));
9047 let c2: Cow<'_, str> = Cow::Owned(s);
9050 let mut c3: Cow<'_, str> = Cow::Borrowed("bye");
16226 use crate::borrow::{Cow, ToOwned};
16679 /// This function returns a [`Cow<'a, str>`]. If our byte slice is invalid
16685 /// [`Cow<'a, str>`]: crate::borrow::Cow
16710 pub fn from_utf8_lossy(v: &[u8]) -> Cow<'_, str> {
16717 return Cow::Borrowed(valid);
16721 return Cow::Borrowed("");
16739 Cow::Owned(res)
16779 /// Unlike [`from_utf8_lossy`] which returns a [`Cow<'a, str>`],
16784 /// [`Cow<'a, str>`]: crate::borrow::Cow
17988 impl<'a> FromIterator<Cow<'a, str>> for String {
17989 fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(iter: I) -> String {
18075 impl<'a> Extend<Cow<'a, str>> for String {
18076 fn extend<I: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: I) {
18081 fn extend_one(&mut self, s: Cow<'a, str>) {
18175 impl_eq! { Cow<'a, str>, str }
18176 impl_eq! { Cow<'a, str>, &'b str }
18177 impl_eq! { Cow<'a, str>, String }
18471 impl ToString for Cow<'_, str> {
18581 impl<'a> From<Cow<'a, str>> for String {
18582 fn from(s: Cow<'a, str>) -> String {
18588 impl<'a> From<&'a str> for Cow<'a, str> {
18596 /// # use std::borrow::Cow;
18597 /// assert_eq!(Cow::from("eggplant"), Cow::Borrowed("eggplant"));
18600 fn from(s: &'a str) -> Cow<'a, str> {
18601 Cow::Borrowed(s)
18606 impl<'a> From<String> for Cow<'a, str> {
18614 /// # use std::borrow::Cow;
18617 /// assert_eq!(Cow::from(s), Cow::<'static, str>::Owned(s2));
18620 fn from(s: String) -> Cow<'a, str> {
18621 Cow::Owned(s)
18626 impl<'a> From<&'a String> for Cow<'a, str> {
18634 /// # use std::borrow::Cow;
18636 /// assert_eq!(Cow::from(&s), Cow::Borrowed("eggplant"));
18639 fn from(s: &'a String) -> Cow<'a, str> {
18640 Cow::Borrowed(s.as_str())
18645 impl<'a> FromIterator<char> for Cow<'a, str> {
18646 fn from_iter<I: IntoIterator<Item = char>>(it: I) -> Cow<'a, str> {
18647 Cow::Owned(FromIterator::from_iter(it))
18652 impl<'a, 'b> FromIterator<&'b str> for Cow<'a, str> {
18653 fn from_iter<I: IntoIterator<Item = &'b str>>(it: I) -> Cow<'a, str> {
18654 Cow::Owned(FromIterator::from_iter(it))
18659 impl<'a> FromIterator<String> for Cow<'a, str> {
18660 fn from_iter<I: IntoIterator<Item = String>>(it: I) -> Cow<'a, str> {
18661 Cow::Owned(FromIterator::from_iter(it))
18830 use Cow::*;
18833 impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B>
18912 /// The type `Cow` is a smart pointer providing clone-on-write functionality: it
18917 /// `Cow` implements `Deref`, which means that you can call
18930 /// use std::borrow::Cow;
18932 /// fn abs_all(input: &mut Cow<[i32]>) {
18944 /// let mut input = Cow::from(&slice[..]);
18949 /// let mut input = Cow::from(&slice[..]);
18953 /// let mut input = Cow::from(vec![-1, 0, 1]);
18957 /// Another example showing how to keep `Cow` in a struct:
18960 /// use std::borrow::Cow;
18963 /// values: Cow<'a, [X]>,
18967 /// fn new(v: Cow<'a, [X]>) -> Self {
18976 /// Items { values: Cow::Borrowed(b) } => println!("borrowed {:?}", b),
18987 /// Items { values: Cow::Owned(_) } => println!("clone_on_write contains owned data"),
18992 pub enum Cow<'a, B: ?Sized + 'a>
19006 impl<B: ?Sized + ToOwned> Clone for Cow<'_, B> {
19025 impl<B: ?Sized + ToOwned> Cow<'_, B> {
19032 /// use std::borrow::Cow;
19034 /// let cow = Cow::Borrowed("moo");
19037 /// let bull: Cow<'_, str> = Cow::Owned("...moo?".to_string());
19055 /// use std::borrow::Cow;
19057 /// let cow: Cow<'_, str> = Cow::Owned("moo".to_string());
19060 /// let bull = Cow::Borrowed("...moo?");
19076 /// use std::borrow::Cow;
19078 /// let mut cow = Cow::Borrowed("foo");
19083 /// Cow::Owned(String::from("FOO")) as Cow<str>
19106 /// Calling `into_owned` on a `Cow::Borrowed` clones the underlying data
19107 /// and becomes a `Cow::Owned`:
19110 /// use std::borrow::Cow;
19113 /// let cow = Cow::Borrowed(s);
19121 /// Calling `into_owned` on a `Cow::Owned` is a no-op:
19124 /// use std::borrow::Cow;
19127 /// let cow: Cow<str> = Cow::Owned(String::from(s));
19144 impl<B: ?Sized + ToOwned> Deref for Cow<'_, B> {
19156 impl<B: ?Sized> Eq for Cow<'_, B> where B: Eq + ToOwned {}
19159 impl<B: ?Sized> Ord for Cow<'_, B>
19170 impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, C>> for Cow<'a, B>
19176 fn eq(&self, other: &Cow<'b, C>) -> bool {
19182 impl<'a, B: ?Sized> PartialOrd for Cow<'a, B>
19187 fn partial_cmp(&self, other: &Cow<'a, B>) -> Option<Ordering> {
19193 impl<B: ?Sized> fmt::Debug for Cow<'_, B>
19206 impl<B: ?Sized> fmt::Display for Cow<'_, B>
19219 impl<B: ?Sized> Default for Cow<'_, B>
19223 /// Creates an owned Cow<'a, B> with the default value for the contained owned value.
19230 impl<B: ?Sized> Hash for Cow<'_, B>
19241 impl<T: ?Sized + ToOwned> AsRef<T> for Cow<'_, T> {
19248 impl<'a> Add<&'a str> for Cow<'a, str> {
19249 type Output = Cow<'a, str>;
19259 impl<'a> Add<Cow<'a, str>> for Cow<'a, str> {
19260 type Output = Cow<'a, str>;
19263 fn add(mut self, rhs: Cow<'a, str>) -> Self::Output {
19270 impl<'a> AddAssign<&'a str> for Cow<'a, str> {
19273 *self = Cow::Borrowed(rhs)
19275 if let Cow::Borrowed(lhs) = *self {
19278 *self = Cow::Owned(s);
19286 impl<'a> AddAssign<Cow<'a, str>> for Cow<'a, str> {
19287 fn add_assign(&mut self, rhs: Cow<'a, str>) {
19291 if let Cow::Borrowed(lhs) = *self {
19294 *self = Cow::Owned(s);
19764 use crate::borrow::{Cow, ToOwned};
21313 impl<'a, B> From<Cow<'a, B>> for Rc<B>
21319 fn from(cow: Cow<'a, B>) -> Rc<B> {
21321 Cow::Borrowed(s) => Rc::from(s),
21322 Cow::Owned(s) => Rc::from(s),
23298 use crate::borrow::{Cow, ToOwned};
25654 impl<'a, B> From<Cow<'a, B>> for Arc<B>
25660 fn from(cow: Cow<'a, B>) -> Arc<B> {
25662 Cow::Borrowed(s) => Arc::from(s),
25663 Cow::Owned(s) => Arc::from(s),
46877 use crate::borrow::{Cow, ToOwned};
49582 impl<'a, T> From<Cow<'a, [T]>> for Vec<T>
49595 /// # use std::borrow::Cow;
49596 /// let o: Cow<[i32]> = Cow::Owned(vec![1, 2, 3]);
49597 /// let b: Cow<[i32]> = Cow::Borrowed(&[1, 2, 3]);
49600 fn from(s: Cow<'a, [T]>) -> Vec<T> {
49877 use crate::borrow::Cow;
49883 impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
49884 fn from(s: &'a [T]) -> Cow<'a, [T]> {
49885 Cow::Borrowed(s)
49890 impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
49891 fn from(v: Vec<T>) -> Cow<'a, [T]> {
49892 Cow::Owned(v)
49897 impl<'a, T: Clone> From<&'a Vec<T>> for Cow<'a, [T]> {
49898 fn from(v: &'a Vec<T>) -> Cow<'a, [T]> {
49899 Cow::Borrowed(v.as_slice())
49904 impl<'a, T> FromIterator<T> for Cow<'a, [T]>
49908 fn from_iter<I: IntoIterator<Item = T>>(it: I) -> Cow<'a, [T]> {
49909 Cow::Owned(FromIterator::from_iter(it))
49913 use crate::borrow::Cow;
49940 __impl_slice_eq1! { [A: Allocator] Cow<'_, [T]>, Vec<U, A> where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
49941 __impl_slice_eq1! { [] Cow<'_, [T]>, &[U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
49942 __impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
49952 //__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, [B; N], }
49953 //__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &[B; N], }
49954 //__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &mut [B; N], }
50324 use crate::borrow::Cow;
51413 impl<T: Copy> From<Cow<'_, [T]>> for Box<[T]> {
51415 fn from(cow: Cow<'_, [T]>) -> Box<[T]> {
51417 Cow::Borrowed(slice) => Box::from(slice),
51418 Cow::Owned(slice) => Box::from(slice),
51442 impl From<Cow<'_, str>> for Box<str> {
51444 fn from(cow: Cow<'_, str>) -> Box<str> {
51446 Cow::Borrowed(s) => Box::from(s),
51447 Cow::Owned(s) => Box::from(s),