pub trait Freeze {
type Frozen;
// Required method
fn freeze(self, freezer: &Freezer) -> Result<Self::Frozen>;
}
Expand description
Need to be implemented for non-simple StarlarkValue
.
This is called on freeze of the heap. Must produce a replacement object to place in the frozen heap.
For relatively simple cases it can be implemented with #[derive(Freeze)]
:
use starlark::values::Freeze;
#[derive(Freeze)]
struct MyType<V> {
value: V,
// This field does not implement `Freeze`, but we can use it as is for freeze.
#[freeze(identity)]
data: AdditionalData,
}
Required Associated Types§
Required Methods§
sourcefn freeze(self, freezer: &Freezer) -> Result<Self::Frozen>
fn freeze(self, freezer: &Freezer) -> Result<Self::Frozen>
Freeze a value. The frozen value must be equal to the original, and produce the same hash.
Note during freeze, Value
objects in Self
might be already special forward-objects,
trying to unpack these objects will crash the process.
So the function is only allowed to access Value
objects after it froze them.