diff options
author | JJ | 2024-05-10 01:00:01 +0000 |
---|---|---|
committer | JJ | 2024-05-10 02:41:52 +0000 |
commit | 073c902a31936c2b53d89245662fb272c9670169 (patch) | |
tree | a8789ed4561dc4c3dde84489a600272cbd5f806b /std/prelude/convert.pk | |
parent | 51c8b349a77a8d8b1b34ce8e03518dad6e3cba00 (diff) |
std: sweeping changes.
- replace interfaces with classes
- replace : with then and do
- solidify memory management as rust-style ownership
- replace unsafe blocks with safe/unsafe attributes
- add magic and copy attributes
- switch Coerce impl from from to to
Diffstat (limited to 'std/prelude/convert.pk')
-rw-r--r-- | std/prelude/convert.pk | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/std/prelude/convert.pk b/std/prelude/convert.pk index 6abf543..ec1a4a7 100644 --- a/std/prelude/convert.pk +++ b/std/prelude/convert.pk @@ -1,23 +1,19 @@ -## std.convert: Interfaces for type coersion and conversion. +## std.convert: Classes for type coersion and conversion. ## This module is imported by default. -## The Coerce interface is used for type conversion that will not fail. +## The Coerce class is used for type conversion that will not fail. ## Its associated methods, `from` and `into`, are used internally ## by the compiler for implicit type conversion (coersion). -pub type Coerce[T] = interface - from(T): Self - # into(Self): T +pub type Coerce[T] = class + to(Self): T + # from(T): Self -## The `into` function is automatically implemented for all types that -## implement `from`: that is, all types U that are convertable to T. -pub func into[T, U: Coerce[T]](self: T): U = - from(self) +## The `from` function is automatically implemented for all types that +## implement `to`: that is, all types T that are convertable to U. +pub func from[T: Coerce[U], U](self: U): T = + to(self) -## The Convert interface is used for type conversion that may fail. +## The Convert class is used for type conversion that may fail. # We'll see what this breaks. -pub type Convert[T] = interface - from(T): Self?! - -## A blanket implementation of a corresponding `into` function. -pub func into[T, U: Convert[T]](self: T): U = - from(self) +pub type Convert[T, E] = class + to(Self): Result[T, E] |