with_owned

guppylang.std.mem.with_owned(val: T, f: Callable[[T], tuple[Out, T]]) Out[source]

Runs a closure where the borrowed argument is promoted to an owned one.

The closure should return two values:

  • A generic return value that will be passed through.

  • Another value of type T that is written back into the borrowed place. This can either be the original passed value, or a new value of the same type that was created in the closure.

Pretending that val is a pointer, this would be equivalent to the following operation in Rust/C: (out, *val) = f(*val)