mirror of
https://github.com/erg-lang/erg.git
synced 2025-12-23 05:36:48 +00:00
1.3 KiB
1.3 KiB
module unsound
Ergの型システムでは安全が保証できない、不安全で不健全な操作を行うAPIを提供します。
unsafe!
Unsafe
Executes a Unsafe procedure. Just like Rust, Unsafe APIs cannot be called directly, but are all passed as higher-order functions to this procedure.
unsound = import "unsound"
i = unsound.unsafe! do!:
# convert `Result Int` to `Int`
unsound.transmute input!().try_into(Int), Int
transmute
第1引数のオブジェクトを第2引数の型へ変換します。型チェックは行われません。 この関数は型システムの型安全性を損ないます。使用の際はバリデーション等を行ってください。
auto_transmute
transmuteとは違い、期待される型に自動で変換します。OcamlのObj.magicと同じ働きをします。