Partial move field syntax in method signature

struct Point{
  x: i32,
  y: i32
}
impl Point{
  fn move_x(self){
    self.x
  }
  fn move_x_rfc(self::M)
  where M: self::x
  {
     self.x
  }
  fn move_y(self){
    self.y
  }
  fn move_y_rfc(self::M)
   where M:: self.y
  {
     self.y
  }
}
fn test(){
  let pt = Point::new(3, 4);
  let xx = pt.move_x(); // ok
  let yy = pt.move_y(); // error, use moved Point
  // Is there syntax support for specifying partial moves in method signatures, where only certain fields are moved when the method is called?
}
// Using Option to enable partial moves
struct Point {
    x: Option<i32>,
    y: Option<i32>
}

impl Point {
    fn move_x(&mut self) -> i32 {
        self.x.take().unwrap() // Adds syntax noise
    }
}

// Usage becomes more verbose
let mut pt = Point { 
    x: Some(3), 
    y: Some(4) 
};
let x = pt.move_x(); // Now we need to deal with Option everywhere

While this approach works technically, it introduces:

  • Additional type complexity with Option wrappers

  • Extra syntax noise in business logic (Some/unwrap)

  • Mental overhead of tracking Option states

This seems like overengineering for what should be a simpler ownership problem.

I would suggest including prose to explain what you're looking to do.

But also, you might be interested in https://smallcultfollowing.com/babysteps/blog/2024/06/02/the-borrow-checker-within/#step-3-view-types-and-interprocedural-borrows.

2 Likes