into
stdlib/core/into.hk: explicit conversion from one type into another.
Self is the source and To is the target. The target uses a trait slot. This permits one source to implement several useful conversions. A bounded caller names the slot (S: Into<HttpError>), and the dictionary fixes the result type before the body calls s.into().
There is one direction and no blanket twin. Hanki has no blanket impls; a reverse From trait would duplicate every conversion pair. Conversion bodies are semantic choices and are not derived.
Into
trait Into<To>
into
def into(self) -> To
Convert self into To.
@no-doctest: a useful example needs a concrete source, target and impl; the bounded two-target dispatch is exercised by this module's test below
_Source
struct _Source
value: int
end
Private fixtures keep the trait's two-target dispatch executable without adding example-only names to core's public surface.
_Label
struct _Label
value: string
end
_Count
struct _Count
value: int
end
impl Into<Source, Label>
into
def into(self) -> _Label
Convert the private test source to its label target.
@no-doctest: private test fixture covered by the module test below
impl Into<Source, Count>
into
def into(self) -> _Count
Convert the private test source to its count target.
@no-doctest: private test fixture covered by the module test below
aslabel
def _as_label<S: Into<_Label>>(source: S) -> _Label
ascount
def _as_count<S: Into<_Count>>(source: S) -> _Count