Trait std::borrow::BorrowMut

1.0.0 · source ·
pub trait BorrowMut<Borrowed>: Borrow<Borrowed>where
    Borrowed: ?Sized,{
    // Required method
    fn borrow_mut(&mut self) -> &mut Borrowed;
}
Expand description

用于可变借用数据的 trait。

作为 Borrow<T> 的同伴,这个 trait 允许一个类型通过提供一个可变引用作为底层类型借用。 请参见 Borrow<T>,以了解更多有关借用另一种类型的信息。

Required Methods§

source

fn borrow_mut(&mut self) -> &mut Borrowed

从拥有的值中借用。

Examples
use std::borrow::BorrowMut;

fn check<T: BorrowMut<[i32]>>(mut v: T) {
    assert_eq!(&mut [1, 2, 3], v.borrow_mut());
}

let v = vec![1, 2, 3];

check(v);
Run

Implementors§

1.36.0 · source§

impl BorrowMut<str> for String

source§

impl<T> BorrowMut<T> for &mut Twhere T: ?Sized,

source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

impl<T, A> BorrowMut<[T]> for Vec<T, A>where A: Allocator,

1.1.0 · source§

impl<T, A> BorrowMut<T> for Box<T, A>where A: Allocator, T: ?Sized,

1.4.0 · source§

impl<T, const N: usize> BorrowMut<[T]> for [T; N]