Updated highlighting
This commit is contained in:
@@ -10,7 +10,7 @@ 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.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
public class Logger {
|
||||
String prefix;
|
||||
|
||||
@@ -28,7 +28,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.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
public constructor(str* prefix) {
|
||||
self.prefix = prefix.to_string();
|
||||
}
|
||||
@@ -38,7 +38,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.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
public void warning(self*, str* message) {
|
||||
self.log(LogLevel::Warning, message);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public void warning(self*, str* message) {
|
||||
|
||||
One of Mist's most powerful features is the ability to nest trait implementations directly within the class block. This keeps the logic for how a type behaves (e.g., how it is displayed) physically coupled with the type definition.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
impl fmt::Display {
|
||||
std::fmt::Result fmt(self*, std::fmt::Formatter<'_> mut* f) {
|
||||
return write!(f, "logger ({})", self.prefix);
|
||||
|
||||
@@ -10,7 +10,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.
|
||||
|
||||
```rust
|
||||
```mist
|
||||
public enum TaskState {
|
||||
Pending,
|
||||
InProgress,
|
||||
@@ -26,7 +26,7 @@ public enum TaskState {
|
||||
|
||||
Mist supports all standard variant shapes, ensuring a 1:1 mapping to the underlying Rust execution model.
|
||||
|
||||
```rust
|
||||
```mist
|
||||
enum Message {
|
||||
Quit, // Unit
|
||||
Move(i32, i32), // Tuple
|
||||
@@ -40,7 +40,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.
|
||||
|
||||
```rust
|
||||
```mist
|
||||
public enum Validation<'a, T> {
|
||||
Valid(T),
|
||||
Invalid {
|
||||
|
||||
@@ -10,7 +10,7 @@ Functions are the primary unit of execution in Mist. They prioritize a tradition
|
||||
|
||||
A standard function requires a return type, a name, and a body. Use the `void` keyword for functions that do not return a value.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
i32 add(i32 a, i32 b) {
|
||||
return a + b;
|
||||
}
|
||||
@@ -24,7 +24,7 @@ void log_status(str* message) {
|
||||
|
||||
Functions are private to their module by default. The `public` modifier exports the function for cross-module access.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
public i32 get_version() {
|
||||
return 1;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public i32 get_version() {
|
||||
|
||||
Parameters follow Rust’s ownership rules but use Mist’s local variable syntax. Use `mut` to allow a function to modify its local binding of a value.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
void update_score(i32 mut current_score, i32 bonus) {
|
||||
current_score = current_score + bonus;
|
||||
}
|
||||
@@ -44,7 +44,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.
|
||||
|
||||
```rust
|
||||
```mist
|
||||
public str'a* choose_longer<'a, T: Display>(str'a* s1, str'a* s2, T meta) {
|
||||
println!("Metadata: {}", meta);
|
||||
return if (s1.len() > s2.len()) { s1 } else { s2 };
|
||||
@@ -55,7 +55,7 @@ public str'a* choose_longer<'a, T: Display>(str'a* s1, str'a* s2, T meta) {
|
||||
|
||||
Metadata is applied via the `#[attr]` syntax directly above the declaration for compiler hints or testing.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
#[inline]
|
||||
public bool is_active(u32 id) {
|
||||
return id > 0;
|
||||
|
||||
@@ -10,7 +10,7 @@ Mist simplifies Rust’s reference system by using a pointer-style syntax. While
|
||||
|
||||
References are defined by placing a `*` after the type. By default, pointers are immutable (shared). To allow modification of the underlying data, use the `mut*` modifier.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
void increment(i32 mut* value, i32* limit) {
|
||||
if (value < limit) {
|
||||
value = value + 1;
|
||||
@@ -22,7 +22,7 @@ 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.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
public struct Inspector<'a> {
|
||||
public str'a* target,
|
||||
public u32'a mut* counter,
|
||||
|
||||
@@ -10,7 +10,7 @@ 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.
|
||||
|
||||
```rust
|
||||
```mist
|
||||
public struct Task {
|
||||
public String name,
|
||||
public TaskState state,
|
||||
@@ -22,7 +22,7 @@ public struct Task {
|
||||
|
||||
Use the `public` modifier to make the struct or its individual fields accessible from other modules.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
public struct NetworkNode {
|
||||
public u32 id,
|
||||
str* address,
|
||||
@@ -33,7 +33,7 @@ public struct NetworkNode {
|
||||
|
||||
Structs are instantiated using the standard brace syntax.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
var task = Task {
|
||||
name: "Initialize".to_string(),
|
||||
state: TaskState::Pending,
|
||||
@@ -45,7 +45,7 @@ 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.
|
||||
|
||||
```cpp
|
||||
```mist
|
||||
public struct Buffer<'a, T> {
|
||||
public T'a* data,
|
||||
public usize len,
|
||||
|
||||
@@ -10,7 +10,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.
|
||||
|
||||
```rust
|
||||
```mist
|
||||
public trait Drawable {
|
||||
void draw(self*);
|
||||
str* metadata(self*);
|
||||
@@ -20,7 +20,7 @@ public trait Drawable {
|
||||
|
||||
To implement a trait for a specific type, use the `impl` keyword followed by the trait name and the target type. This block must contain all required methods defined in the trait.
|
||||
|
||||
```rust
|
||||
```mist
|
||||
impl Drawable for Task {
|
||||
void draw(self*) {
|
||||
println!("Drawing task: {}", self.name);
|
||||
@@ -35,7 +35,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.
|
||||
|
||||
```rust
|
||||
```mist
|
||||
public trait Identifiable {
|
||||
u32 get_id(self*);
|
||||
|
||||
@@ -48,7 +48,7 @@ public trait Identifiable {
|
||||
|
||||
Traits can build upon other traits. If a trait requires another trait to be implemented first, use the colon `:` syntax.
|
||||
|
||||
```rust
|
||||
```mist
|
||||
public trait Animated : Drawable {
|
||||
void animate(self*, f32 delta_time);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user