webrust 0.2.0

Python-like Rust for Web Applications - A bridge between Python simplicity and Rust power
Documentation

webrust - Python-like Rust for Web Applications

Crates.io Documentation License: MIT

webrust is a revolutionary Rust crate that bridges the elegance of Python with the power and safety of Rust. It provides a seamless web-based interface for Rust applications, featuring Python-like syntax, advanced f-string formatting, real-time type validation, and mathematical rendering capabilities.

🚀 Philosophy

webrust serves as both a bridge between Python and Rust and a catalyst for Rust's evolution toward simplicity. We believe that Rust's power shouldn't come at the cost of developer experience. By introducing Python-like ergonomics while maintaining Rust's core strengths, webrust demonstrates how systems programming can be both safe and simple.

✨ Key Features

  • 🐍 Python-like Syntax: Familiar input/output patterns with Rust's type safety
  • 🎨 Advanced F-Strings: Rust expressions in string formatting with :c and :j specifiers
  • 🌐 Web Interface: Automatic browser integration with smart server management
  • 🔒 Type Safety: Real-time input validation with detailed error messages
  • 📊 LaTeX Rendering: Mathematical expressions via MathJax integration
  • 🎭 Rich Styling: CSS-like styling directly in Rust code
  • ⚡ Zero Configuration: Works out of the box with automatic setup

🏁 Quick Start

Add webrust to your Cargo.toml:

[dependencies]

webrust = "0.1.0"

Create your first webrust application:

use webrust::prelude::*;

#[gui]
fn main() {
    println("@(blue, bold)🎯 Welcome to webrust!");
    
    let name: String = input("What's your name?");
    let age: i32 = input("How old are you?");
    
    println("Hello @(green, bold){name}@(reset)! You are @(yellow){age}@(reset) years old.");
    
    if age >= 18 {
        println("@(green)✅ You're an adult!");
    } else {
        println("@(orange)🧒 You're still young!");
    }
    
    // Mathematical expressions
    latex("\\text{The quadratic formula: } x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}");
}

Run with:

cargo run

🌐 How the Web Server Works

Unlike traditional console applications, webrust automatically:

  1. Starts a local web server on 127.0.0.1:8080
  2. Opens your default browser to the application
  3. Provides a modern web interface with real-time updates
  4. Handles all communication between Rust and the browser
  5. Shuts down automatically when you close the browser tab/window

🔄 Smart Server Management

No need for Ctrl+C! The server intelligently shuts down:

  • 3 seconds after closing the browser tab/window
  • 5 seconds after the last browser activity
  • 30 seconds maximum runtime (safety limit)

This creates a seamless experience where users can simply close the browser when done.

📚 Advanced Features

F-String Formatting

webrust extends Rust with Python-like f-strings supporting complex expressions:

let numbers = vec![1, 2, 3, 4, 5];
let name = "Alice";

// Basic formatting
println("Hello {name}, you have {numbers.len()} items");

// Advanced expressions with formatting
println("Sum: {numbers.iter().sum::<i32>()}");
println("Data: {numbers:c}");           // Compact format
println("Pretty: {numbers:j}");         // JSON-like format

// Conditional expressions
let status = if numbers.len() > 3 { "many" } else { "few" };
println("You have {status} items");

Type-Safe Input

Automatic type validation with helpful error messages:

let age: i32 = input("Enter your age:");           // Validates integer
let height: f64 = input("Enter height (m):");      // Validates float  
let married: bool = input("Married (true/false):"); // Validates boolean
let initial: char = input("First initial:");        // Validates single char

Mathematical Rendering

High-quality LaTeX rendering for scientific applications:

// Equations
latex("E = mc^2");
latex("\\nabla \\times \\vec{E} = -\\frac{\\partial \\vec{B}}{\\partial t}");

// Matrices
latex("\\begin{pmatrix} 1 & 0 \\\\ 0 & 1 \\end{pmatrix}");

// Data tables
latex("\\begin{array}{|c|c|c|}
    \\hline
    \\text{Item} & \\text{Qty} & \\text{Price} \\\\
    \\hline
    \\text{Apple} & 5 & \\$2.50 \\\\
    \\text{Orange} & 3 & \\$1.80 \\\\
    \\hline
    \\end{array}");

Rich Text Styling

CSS-like styling directly in Rust:

println("@(red, bold)Error:@(reset) Operation failed");
println("@(green, italic)Success:@(reset) @(blue, underline)All done!@(reset)");
println("@(yellow, bg-black) Warning @(reset)");

🛠 Examples

The crate includes comprehensive examples:

  • simpleio: Basic input/output with validation
  • format: Advanced f-string formatting demonstrations
  • latex: Mathematical and scientific rendering

Run examples with:

cargo run --example simpleio

cargo run --example format

cargo run --example latex

🔮 Roadmap

webrust is actively evolving with new Python-like features in development:

Planned Features

  • range(start, end, step) - Python-style range generation
  • enumerate(iterable) - Index-value iteration
  • zip(iter1, iter2) - Parallel iteration
  • len(container) - Universal length function
  • sum(iterable) - Summation with type inference
  • sorted(iterable) - Sorting with custom comparisons
  • List comprehensions - Pythonic data transformation
  • Pattern matching enhancements - More intuitive syntax
  • Decorator-like attributes - Enhanced macro system

Future Directions

  • Performance optimizations for large-scale applications
  • Plugin system for extending functionality
  • IDE integration with enhanced tooling support
  • Cross-platform mobile support via web technologies

🤝 Contributing

webrust welcomes contributions! We're particularly interested in:

  • New Python-like features that enhance Rust's ergonomics
  • Performance improvements and optimizations
  • Documentation and example improvements
  • Testing across different platforms and use cases

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🌟 Why webrust?

For Python Developers: Ease into Rust with familiar syntax while gaining performance and safety.

For Rust Developers: Enjoy simplified APIs without sacrificing Rust's core benefits.

For Educators: Teach systems programming concepts with approachable syntax.

For Scientists: Display mathematical content with publication-quality rendering.

For Innovators: Prototype quickly with web-based interfaces and rich formatting.


webrust: Making Rust as simple as Python, as powerful as ever. 🦀✨

Coming soon to crates.io and GitHub!