replace
Assinatura
replace<T>(destination: T, source: T): Treplace armazena source em um binding local mutável e retorna o valor antes armazenado nele. Aceita tipos Copy e string. Para string, os dois argumentos devem ser bindings locais mutáveis; source é movido e não pode ser usado após a chamada.
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;`