Skip to content

Commit 4555fe2

Browse files
Guest0x0bobzhang
authored andcommitted
port trait implementation to impl
1 parent 8dd7795 commit 4555fe2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+511
-455
lines changed

array/array.mbti

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ impl FixedArray {
3131
new[T](Int, () -> T) -> Self[T] //deprecated
3232
new_with_index[T](Int, (Int) -> T) -> Self[T] //deprecated
3333
op_add[T](Self[T], Self[T]) -> Self[T]
34-
op_equal[T : Eq](Self[T], Self[T]) -> Bool
3534
rev[T](Self[T]) -> Self[T]
3635
rev_each[T](Self[T], (T) -> Unit) -> Unit
3736
rev_eachi[T](Self[T], (Int, T) -> Unit) -> Unit
@@ -46,6 +45,7 @@ impl FixedArray {
4645
starts_with[T : Eq](Self[T], Self[T]) -> Bool
4746
swap[T](Self[T], Int, Int) -> Unit
4847
}
48+
impl[T : Eq] Eq for FixedArray[T]
4949
impl[X : @quickcheck.Arbitrary] @quickcheck.Arbitrary for FixedArray[X]
5050

5151
impl Array {

array/fixedarray.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ test "ends_with" {
960960
/// inspect!(arr1 == arr3, content="false")
961961
/// }
962962
/// ```
963-
pub fn FixedArray::op_equal[T : Eq](
963+
pub impl[T : Eq] Eq for FixedArray[T] with op_equal(
964964
self : FixedArray[T],
965965
that : FixedArray[T]
966966
) -> Bool {

buffer/buffer.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub fn new(size_hint~ : Int = 0) -> T {
190190
/// )
191191
/// }
192192
/// ```
193-
pub fn write_string(self : T, value : String) -> Unit {
193+
pub impl Logger for T with write_string(self, value) {
194194
self.grow_if_necessary(self.len + value.length() * 2)
195195
self.data.blit_from_string(self.len, value, 0, value.length())
196196
self.len += value.length() * 2
@@ -614,7 +614,7 @@ pub fn write_bytesview(self : T, value : @bytes.View) -> Unit {
614614
/// )
615615
/// }
616616
/// ```
617-
pub fn write_substring(
617+
pub impl Logger for Buffer with write_substring(
618618
self : T,
619619
value : String,
620620
start : Int,
@@ -646,7 +646,7 @@ pub fn write_substring(
646646
/// )
647647
/// }
648648
/// ```
649-
pub fn write_char(self : T, value : Char) -> Unit {
649+
pub impl Logger for Buffer with write_char(self : T, value : Char) -> Unit {
650650
self.grow_if_necessary(self.len + 4)
651651
let inc = self.data.set_utf16le_char(self.len, value)
652652
self.len += inc

buffer/buffer.mbti

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ impl T {
1919
write_byte(Self, Byte) -> Unit
2020
write_bytes(Self, Bytes) -> Unit
2121
write_bytesview(Self, @bytes.View) -> Unit
22-
write_char(Self, Char) -> Unit
2322
write_double_be(Self, Double) -> Unit
2423
write_double_le(Self, Double) -> Unit
2524
write_float_be(Self, Float) -> Unit
@@ -30,14 +29,13 @@ impl T {
3029
write_int_le(Self, Int) -> Unit
3130
write_iter(Self, Iter[Byte]) -> Unit
3231
write_object(Self, &Show) -> Unit
33-
write_string(Self, String) -> Unit
3432
write_sub_string(Self, String, Int, Int) -> Unit //deprecated
35-
write_substring(Self, String, Int, Int) -> Unit
3633
write_uint64_be(Self, UInt64) -> Unit
3734
write_uint64_le(Self, UInt64) -> Unit
3835
write_uint_be(Self, UInt) -> Unit
3936
write_uint_le(Self, UInt) -> Unit
4037
}
38+
impl Logger for T
4139
impl Show for T
4240

4341
// Type aliases

builtin/array.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub fn Array::op_set[T](self : Array[T], index : Int, value : T) -> Unit {
241241
/// inspect!(arr1 == arr3, content="false")
242242
/// }
243243
/// ```
244-
pub fn Array::op_equal[T : Eq](self : Array[T], other : Array[T]) -> Bool {
244+
pub impl[T : Eq] Eq for Array[T] with op_equal(self, other) {
245245
let self_len = self.length()
246246
let other_len = other.length()
247247
guard self_len == other_len else { return false }
@@ -285,7 +285,7 @@ pub fn Array::op_equal[T : Eq](self : Array[T], other : Array[T]) -> Bool {
285285
/// inspect!(arr1.compare(arr1), content="0") // arr1 = arr1
286286
/// }
287287
/// ```
288-
pub fn Array::compare[T : Compare](self : Array[T], other : Array[T]) -> Int {
288+
pub impl[T : Compare] Compare for Array[T] with compare(self, other) {
289289
let len_self = self.length()
290290
let len_other = other.length()
291291
let cmp = len_self.compare(len_other)
@@ -1753,6 +1753,6 @@ pub fn Array::iter2[A](self : Array[A]) -> Iter2[Int, A] {
17531753
/// inspect!(arr.is_empty(), content="true")
17541754
/// }
17551755
/// ```
1756-
pub fn Array::default[T]() -> Array[T] {
1756+
pub impl[T] Default for Array[T] with default() {
17571757
[]
17581758
}

builtin/bigint_js.mbt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,23 @@ pub fn BigInt::to_octets(self : BigInt, length? : Int) -> Bytes {
113113
}
114114

115115
///|
116-
pub extern "js" fn BigInt::compare(self : BigInt, other : BigInt) -> Int =
116+
extern "js" fn BigInt::compare(self : BigInt, other : BigInt) -> Int =
117117
#|(x, y) => x < y ? -1 : x > y ? 1 : 0
118118

119119
///|
120-
pub extern "js" fn BigInt::op_equal(self : BigInt, other : BigInt) -> Bool =
120+
pub impl Compare for BigInt with compare(self, other) {
121+
self.compare(other)
122+
}
123+
124+
///|
125+
extern "js" fn BigInt::equal(self : BigInt, other : BigInt) -> Bool =
121126
#|(x, y) => x === y
122127

128+
///|
129+
pub impl Eq for BigInt with op_equal(self, other) {
130+
self.equal(other)
131+
}
132+
123133
///|
124134
pub extern "js" fn BigInt::from_int(x : Int) -> BigInt =
125135
#|(x) => BigInt(x)

builtin/bigint_nonjs.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ pub fn BigInt::is_zero(self : BigInt) -> Bool {
850850
/// inspect!(a.compare(a), content="0") // 42 = 42
851851
/// }
852852
/// ```
853-
pub fn BigInt::compare(self : BigInt, other : BigInt) -> Int {
853+
pub impl Compare for BigInt with compare(self, other) {
854854
if self.sign != other.sign {
855855
return if self.sign == Positive { 1 } else { -1 }
856856
}
@@ -897,7 +897,7 @@ pub fn BigInt::compare(self : BigInt, other : BigInt) -> Int {
897897
/// inspect!(a == c, content="false")
898898
/// }
899899
/// ```
900-
pub fn BigInt::op_equal(self : BigInt, other : BigInt) -> Bool {
900+
pub impl Eq for BigInt with op_equal(self, other) {
901901
if self.sign != other.sign || self.len != other.len {
902902
return false
903903
}

0 commit comments

Comments
 (0)