Skip to content

Commit

Permalink
docs: Change trait to open and impl to pub.
Browse files Browse the repository at this point in the history
  • Loading branch information
illusory0x0 authored and peter-jerry-ye committed Feb 25, 2025
1 parent 100cdb7 commit 4e134cc
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions next/sources/language/src/trait/top.mbt
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// start trait 1
trait I {
pub(open) trait I {
method_(Int) -> Int
method_with_label(Int, label~: Int) -> Int
//! method_with_label(Int, label?: Int) -> Int
}
// end trait 1

// start trait 2
trait MyShow {
pub(open) trait MyShow {
to_string(Self) -> String
}

struct MyType {}

impl MyShow for MyType with to_string(self) { ... }
pub impl MyShow for MyType with to_string(self) { ... }

struct MyContainer[T] {}

// trait implementation with type parameters.
// `[X : Show]` means the type parameter `X` must implement `Show`,
// this will be covered later.
impl[X : MyShow] MyShow for MyContainer[X] with to_string(self) { ... }
pub impl[X : MyShow] MyShow for MyContainer[X] with to_string(self) { ... }
// end trait 2

// start trait 3
trait J {
pub(open) trait J {
f(Self) -> Unit
f_twice(Self) -> Unit
}
Expand All @@ -36,7 +36,7 @@ impl J with f_twice(self) {
// end trait 3

// start trait 4
trait Number {
pub(open) trait Number {
op_add(Self, Self) -> Self
op_mul(Self, Self) -> Self
}
Expand All @@ -54,11 +54,11 @@ struct Point {
y : Int
} derive(Eq, Show)

impl Number for Point with op_add(self, other) {
pub impl Number for Point with op_add(self, other) {
{ x: self.x + other.x, y: self.y + other.y }
}

impl Number for Point with op_mul(self, other) {
pub impl Number for Point with op_mul(self, other) {
{ x: self.x * other.x, y: self.y * other.y }
}

Expand All @@ -79,7 +79,7 @@ test {
// start trait 8
struct MyCustomType {}

impl Show for MyCustomType with output(self, logger) { ... }
pub impl Show for MyCustomType with output(self, logger) { ... }

fn f() -> Unit {
let x = MyCustomType::{ }
Expand All @@ -105,18 +105,18 @@ test {
// end trait 9

// start super trait 1
trait Position {
pub(open) trait Position {
pos(Self) -> (Int, Int)
}
trait Draw {
pub(open) trait Draw {
draw(Self) -> Unit
}

trait Object : Position + Draw {}
pub(open) trait Object : Position + Draw {}
// end super trait 1

// start trait object 1
trait Animal {
pub(open) trait Animal {
speak(Self) -> String
}

Expand Down Expand Up @@ -159,11 +159,11 @@ test {
// end trait object 1

// start trait object 2
trait Logger {
pub(open) trait Logger {
write_string(Self, String) -> Unit
}

trait CanLog {
pub(open) trait CanLog {
log(Self, &Logger) -> Unit
}

Expand All @@ -172,7 +172,7 @@ fn &Logger::write_object[Obj : CanLog](self : &Logger, obj : Obj) -> Unit {
}

// use the new method to simplify code
impl[A : CanLog, B : CanLog] CanLog for (A, B) with log(self, logger) {
pub impl[A : CanLog, B : CanLog] CanLog for (A, B) with log(self, logger) {
let (a, b) = self
logger
..write_string("(")
Expand Down

0 comments on commit 4e134cc

Please # to comment.