Derive Macro destructure::Mutation

source ·
#[derive(Mutation)]
Expand description

Automatically implements substitute() methods.

When performing loop processing, and so on, it is more efficient than using [reconstruct()].

Usage

use destructure::Mutation;

#[derive(Debug, Mutation)]
pub struct Book {
    id: String,
    name: String,
}

book.substitute(|book| {
    *book.name = "new name".to_string();
});

book.try_substitute(|book| -> Result<(), std::io::Error> {
   *book.name = "new name".to_string();
   Ok(())
}).expect("Error");