Updated visibility
This commit is contained in:
@@ -11,10 +11,10 @@ Classes in Mist bridge the gap between Java's organizational structure and Rust'
|
|||||||
A class groups fields and methods together. Fields follow the `type name` convention, and methods define their logic directly within the class body.
|
A class groups fields and methods together. Fields follow the `type name` convention, and methods define their logic directly within the class body.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public class Logger {
|
pub class Logger {
|
||||||
String prefix;
|
String prefix;
|
||||||
|
|
||||||
public void info(self*, str* message) {
|
pub void info(self*, str* message) {
|
||||||
self.log(LogLevel::Info, message);
|
self.log(LogLevel::Info, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ public class Logger {
|
|||||||
Unlike languages that use the class name for initialization, Mist uses the explicit `constructor` keyword. This makes the entry point of the class unmistakable.
|
Unlike languages that use the class name for initialization, Mist uses the explicit `constructor` keyword. This makes the entry point of the class unmistakable.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public constructor(str* prefix) {
|
pub constructor(str* prefix) {
|
||||||
self.prefix = prefix.to_string();
|
self.prefix = prefix.to_string();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -39,7 +39,7 @@ public constructor(str* prefix) {
|
|||||||
Mist maintains Rust's explicit context handling. Any method that needs to access or modify class data must include `self*` (or `self mut*` for mutations) as its first parameter.
|
Mist maintains Rust's explicit context handling. Any method that needs to access or modify class data must include `self*` (or `self mut*` for mutations) as its first parameter.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public void warning(self*, str* message) {
|
pub void warning(self*, str* message) {
|
||||||
self.log(LogLevel::Warning, message);
|
self.log(LogLevel::Warning, message);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ Enums in Mist serve as powerful algebraic data types (ADTs), maintaining the exa
|
|||||||
An enum can contain unit variants, tuple variants, or struct-like variants. Following Mist's core philosophy, struct-like variants place the type before the identifier.
|
An enum can contain unit variants, tuple variants, or struct-like variants. Following Mist's core philosophy, struct-like variants place the type before the identifier.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public enum TaskState {
|
pub enum TaskState {
|
||||||
Pending,
|
Pending,
|
||||||
InProgress,
|
InProgress,
|
||||||
Completed,
|
Completed,
|
||||||
@@ -41,7 +41,7 @@ enum Message {
|
|||||||
Just like structs and functions, enums declare generics and lifetimes in a unified block. This is particularly useful for defining custom Result or Option types that handle references.
|
Just like structs and functions, enums declare generics and lifetimes in a unified block. This is particularly useful for defining custom Result or Option types that handle references.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public enum Validation<'a, T> {
|
pub enum Validation<'a, T> {
|
||||||
Valid(T),
|
Valid(T),
|
||||||
Invalid {
|
Invalid {
|
||||||
str'a* message,
|
str'a* message,
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void log_status(str* message) {
|
|||||||
Functions are private to their module by default. The `pub` modifier exports the function for cross-module access.
|
Functions are private to their module by default. The `pub` modifier exports the function for cross-module access.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public i32 get_version() {
|
pub i32 get_version() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -45,7 +45,7 @@ void update_score(i32 mut current_score, i32 bonus) {
|
|||||||
Mist integrates type abstraction and memory management into a single generic block. Lifetimes and type parameters share the `< >` bracket following the identifier.
|
Mist integrates type abstraction and memory management into a single generic block. Lifetimes and type parameters share the `< >` bracket following the identifier.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public str'a* choose_longer<'a, T: Display>(str'a* s1, str'a* s2, T meta) {
|
pub str'a* choose_longer<'a, T: Display>(str'a* s1, str'a* s2, T meta) {
|
||||||
println!("Metadata: {}", meta);
|
println!("Metadata: {}", meta);
|
||||||
return if (s1.len() > s2.len()) { s1 } else { s2 };
|
return if (s1.len() > s2.len()) { s1 } else { s2 };
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ Metadata is applied via the `#[attr]` syntax directly above the declaration for
|
|||||||
|
|
||||||
```mist
|
```mist
|
||||||
#[inline]
|
#[inline]
|
||||||
public bool is_active(u32 id) {
|
pub bool is_active(u32 id) {
|
||||||
return id > 0;
|
return id > 0;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ void increment(i32 mut* value, i32* limit) {
|
|||||||
Lifetimes are attached directly to the type before the pointer symbol. This maintains a clean visual flow where the "type-contract" (identity, duration, and mutability) is read from left to right.
|
Lifetimes are attached directly to the type before the pointer symbol. This maintains a clean visual flow where the "type-contract" (identity, duration, and mutability) is read from left to right.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public struct Inspector<'a> {
|
pub struct Inspector<'a> {
|
||||||
public str'a* target,
|
pub str'a* target,
|
||||||
public u32'a mut* counter,
|
pub u32'a mut* counter,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ Structs in Mist follow the same structural logic as Rust, but apply the language
|
|||||||
A struct is defined by its name followed by a block of fields. Each field follows the Mist convention of placing the type before the identifier, separated by commas.
|
A struct is defined by its name followed by a block of fields. Each field follows the Mist convention of placing the type before the identifier, separated by commas.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public struct Task {
|
pub struct Task {
|
||||||
public String name,
|
pub String name,
|
||||||
public TaskState state,
|
pub TaskState state,
|
||||||
public i32 executions,
|
pub i32 executions,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -23,8 +23,8 @@ public struct Task {
|
|||||||
Use the `pub` modifier to make the struct or its individual fields accessible from other modules.
|
Use the `pub` modifier to make the struct or its individual fields accessible from other modules.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public struct NetworkNode {
|
pub struct NetworkNode {
|
||||||
public u32 id,
|
pub u32 id,
|
||||||
str* address,
|
str* address,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -46,9 +46,9 @@ var task = Task {
|
|||||||
Generics and lifetimes are declared in angle brackets after the struct name. Lifetimes are associated with the reference/pointer type within the field declarations.
|
Generics and lifetimes are declared in angle brackets after the struct name. Lifetimes are associated with the reference/pointer type within the field declarations.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public struct Buffer<'a, T> {
|
pub struct Buffer<'a, T> {
|
||||||
public T'a* data,
|
pub T'a* data,
|
||||||
public usize len,
|
pub usize len,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ Traits in Mist define a set of methods that a type must implement, facilitating
|
|||||||
A trait definition lists method signatures that implementing types must satisfy. Like functions, these signatures place the return type before the method name.
|
A trait definition lists method signatures that implementing types must satisfy. Like functions, these signatures place the return type before the method name.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public trait Drawable {
|
pub trait Drawable {
|
||||||
void draw(self*);
|
void draw(self*);
|
||||||
str* metadata(self*);
|
str* metadata(self*);
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ impl Drawable for Task {
|
|||||||
Traits can provide default behavior for methods. Types implementing the trait can choose to override these defaults or use the provided implementation.
|
Traits can provide default behavior for methods. Types implementing the trait can choose to override these defaults or use the provided implementation.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public trait Identifiable {
|
pub trait Identifiable {
|
||||||
u32 get_id(self*);
|
u32 get_id(self*);
|
||||||
|
|
||||||
bool is_valid(self*) {
|
bool is_valid(self*) {
|
||||||
@@ -49,7 +49,7 @@ public trait Identifiable {
|
|||||||
Traits can build upon other traits. If a trait requires another trait to be implemented first, use the colon `:` syntax.
|
Traits can build upon other traits. If a trait requires another trait to be implemented first, use the colon `:` syntax.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
public trait Animated : Drawable {
|
pub trait Animated : Drawable {
|
||||||
void animate(self*, f32 delta_time);
|
void animate(self*, f32 delta_time);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ Inheritance is a major planned feature but is currently **not implemented**.
|
|||||||
|
|
||||||
Be aware that because we are focusing on syntax, keywords and structures may change between minor versions. Currently:
|
Be aware that because we are focusing on syntax, keywords and structures may change between minor versions. Currently:
|
||||||
|
|
||||||
* **Access Modifiers:** `pub` and private defaults are being tested for various contexts (classes vs. structs, or `public(crate)`).
|
* **Access Modifiers:** `pub` and private defaults are being tested for various contexts (classes vs. structs, or `pub(crate)`).
|
||||||
|
|
||||||
|
|
||||||
* **Pointers vs. References:** The `*` syntax for references (e.g., `self mut*`) is the current standard but is subject to refinement based on ecosystem feedback.
|
* **Pointers vs. References:** The `*` syntax for references (e.g., `self mut*`) is the current standard but is subject to refinement based on ecosystem feedback.
|
||||||
|
|||||||
Reference in New Issue
Block a user