Answers for "rust•armanazi•error•[E0614]: cannot be dereferenced"

0

rust•armanazi•error•[E0614]: cannot be dereferenced

//resolved by imp Deref to your customized smartpoiner 
use std::ops::Deref;

impl<T> Deref for MyBox<T> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

//The other e.g
//Resolved by added match x.as_mut() 
fn main() {
  let mut x = Some(2);
match x{
    Some(v) => *v = 42,
    None => {},
}
assert_eq!(x, Some(42));
}


//e.g
let y = 0u32;
println!("{}",*y); // rise error

//to resolve it
  let y = 0u32;
  let x = &y;
  // So here, `x` is a `&u32`, so we can dereference it:
  println!("{}",*x);
Posted by: Guest on March-24-2022

Browse Popular Code Answers by Language