replace
Signature
replace<T>(destination: T, source: T): Treplace stores source in a mutable local binding and returns the value that was previously stored there. It supports Copy types and string. For string, both arguments must be mutable local bindings; source is moved and cannot be used after the call.
tyrus
import { replace } from "tyrus:memory";
function main(): void {
let value: i32 = 4;
const previous: i32 = replace(value, 12);
print(value); // 12
print(previous); // 4
let source: string = "new value";
let destination: string = "old value";
const oldText: string = replace(destination, source);
print(destination); // new value
print(oldText); // old value
}error
tyrus
import { replace } from "tyrus:memory";
function main(): void {
let source: string = "new value";
let destination: string = "old value";
const oldText: string = replace(destination, source);
print(source);
print(destination);
print(oldText);
}text
error[E0382]: use of moved value: `source`
at /src/main.tyr:7:11
print(source);
^^^^^^
at /src/main.tyr:6:50
const oldText: string = replace(destination, source);
^^^^^^ value moved here; borrow `source` instead if it must remain usable
help: borrow `source` at the move site if it must remain usable later
help: for example: `const oldText: &string = &source;`