[−][src]Macro hyperbole::zoom
Access a named field in an hlist.
First form: evaluates to a statement that moves an hlist field into a variable
Immutable: zoom!(new_variable = my_record.field_name)
Mutable: zoom!(mut new_variable = my_record.field_name)
The result will be a statement that extracts a field, binds its value to the specified identifier, and shadows the original hlist with any remaining fields.
The new hlist will be declared as mut
in all cases.
use hyperbole::{r, zoom, R}; let rec = r![x = 1000, y = "hello world"]; zoom!(s = rec.y); assert_eq!(s, "hello world"); // NOTE: 'rec' is now eqivalent to 'let mut rec = r![x = 1000]' zoom!(n = rec.x); assert_eq!(n, 1000); // NOTE: 'rec' is now empty and contains no fields let _: R![] = rec;
Second form: evaluates to an expression that borrows a field
For immutable borrows: zoom!(&my_record.field_name)
For mutable borrows: zoom!(&mut my_record.field_name)
use hyperbole::{r, zoom, R}; let mut rec = r![x = 1000, y = "hello world"]; let _: &u64 = zoom!(&rec.x); let _: &mut u64 = zoom!(&mut rec.x); assert_eq!(1000, *zoom!(&rec.x)); assert_eq!("hello world", *zoom!(&rec.y)); *zoom!(&mut rec.y) = "changed"; assert_eq!("changed", *zoom!(&rec.y)); // the type and mutability of 'rec' has not changed let _: R![x: u64, y: &str] = rec;