webrust - Python-like Rust for Web Applications
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
:cand:jspecifiers - 🌐 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:
[]
= "0.1.0"
Create your first webrust application:
use *;
Run with:
🌐 How the Web Server Works
Unlike traditional console applications, webrust automatically:
- Starts a local web server on
127.0.0.1:8080 - Opens your default browser to the application
- Provides a modern web interface with real-time updates
- Handles all communication between Rust and the browser
- 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!;
let name = "Alice";
// Basic formatting
println;
// Advanced expressions with formatting
println;
println; // Compact format
println; // JSON-like format
// Conditional expressions
let status = if numbers.len > 3 else ;
println;
Type-Safe Input
Automatic type validation with helpful error messages:
let age: i32 = input; // Validates integer
let height: f64 = input; // Validates float
let married: bool = input; // Validates boolean
let initial: char = input; // Validates single char
Mathematical Rendering
High-quality LaTeX rendering for scientific applications:
// Equations
latex;
latex;
// Matrices
latex;
// Data tables
latex;
Rich Text Styling
CSS-like styling directly in Rust:
println;
println;
println;
🛠 Examples
The crate includes comprehensive examples:
simpleio: Basic input/output with validationformat: Advanced f-string formatting demonstrationslatex: Mathematical and scientific rendering
Run examples with:
🔮 Roadmap
webrust is actively evolving with new Python-like features in development:
Planned Features
range(start, end, step)- Python-style range generationenumerate(iterable)- Index-value iterationzip(iter1, iter2)- Parallel iterationlen(container)- Universal length functionsum(iterable)- Summation with type inferencesorted(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. 🦀✨