Skip to content

A compact collection of Rust projects for beginners and intermediates. Covers basic syntax, blockchain, distributed systems, and advanced real-world applications like APIs and event handling, with CI/CD integration. Hands-on and practical!

License

Notifications You must be signed in to change notification settings

Rurutia1027/rust-playground

Repository files navigation

Rust Playground

Rust Playground CI

A collection of Rust-based projects for learning, experimenting, and implementing foundational programming concepts. This repository is perfect for beginners and intermediate developers looking to enhance their Rust skills.


🚀 Projects Overview

Focus:

  • Learning basic Rust syntax and features.
  • Topics include ownership, borrowing, basic data structures, and control flow.

Focus:

  • Dive deeper into Rust while solving real-world distributed systems challenges.
  • Echo Challenge: Implement a simple service that echoes received messages.
  • Unique ID Generation: Build a system that generates globally unique IDs across nodes.
  • Broadcast System: create a gossip-based broadcast system to share messages efficiently.

Focus:

  • Building a basic blockchain in Rust, most of the codes are referring from Blockchain-Rust.
  • Key Features:
    • Genesis block creation.
    • Transaction and block structures.
    • Mining simulation.
    • Hashing and validation logic.

Focus: This tutorial delves into GraphNode, a critical middleware layer for indexing and querying blockchain data, with a focus on Ethereum. We'll lean how Graph Node extract blockchain data, organize it into subgraphs, and store it in relational databases based on a user-defined schema. We also explore how to read and understand Graph Node source codes.

Focus: Building a production-grade Rust application with real-world use cases, such as implementing a key-value store, managing configuraiton environments, integrating with Ethereum, and handling event-driven workflows. This tutorial showcases how to create a robust system that interacts with blockchain data and local databases.

Key Features:

  1. Key-Value Store(KVStore):
  2. Environment Loader and Config Management:
  3. Framework API Binding with Handlers:
  4. Ethereum Event Subscription:
  5. Data Synchronization to Local Database:
  6. Monitoring Blockchain Events:
  7. Handler and Listener Design:

Project Files:

  • Code and examples are in the tutorial-5 folder.
  • Contains implementations for KVStore, Database Operations, Ethereum event monitoring & handling, and API bindings.

Goals:

  • Provide a clear path to building production-ready applications.
  • Combine blockchain intergration with local database management.
  • Enhance understanding of Rust's ecosystem, async programming, and database interactions.

References: We referred to several amazing open-source repositories, listed below with brief descriptions:

  • eth-analysis-rs: A Rust-based toolkit for analyzing Ethereum blockchain data, including transaction tracing and state changes.
  • mars: A service for querying and storing Ethereum data efficiently, providing a robust data pipeline for blockchain analysis.

Focus:

  • Methods for using streams and implementing iterators with generic support.
  • Implementing test cases for streams and custom iterators.
  • Further exploration of popular third-party stream libraries, with executable test cases demostrating their usage.

Key Features:

  • Generic Stream Handling: Learn how to create, manipulate, and process generic data streams asynchronously in Rust.
  • Custom Generic Iterators: Understand how to implement custom iterators with generics, leveraging Rust's iterator traits for lexible data types.
  • Testing Streams and Iterators: Develop comprehensive test cases for both streams and iterators, ensuring robust and reliable data processing.
  • Third-Party Libraries: Explore libraries like futures, tokio-stream, and others to enhance stream functionality and integrate with async tasks.
  • Practical Applications: Hands-on examples of subscribing to external data sources, mocking data streams, and manipulating streamed data in real time.

Focus:

  • Learning how to integrate and utilize the Progress struct from the pit_wall crate.
  • Implementing real-time progress tracking in Rust applications.
  • Creating custom progress indicators and handling progress updates efficiently.

Key Features:

  • Integration with pit_wall: Step-by-step guidance on adding and configuring the pit_wall crate in our Rust project(integrate with multi-threads, async, iterator and streams together).
  • Using Progress Struct: Detailed exploration of the Progress struct's capabilities, methods and customization options.
  • Custom Progress Indicators: Learn to design and implment our own progress indicators tailored to specific tasks.
  • Real-Time Progress Tracking: Techniques to track and display progress in long-running tasks or asynchronous operations.
  • Testing Progress Logic: Writing test cases to ensure accurate progress tracking and handling edge cases.
  • Practical Examples: Implementing progress tracking in real-world scenarios, such as file downloads, data processing, and API requests.

🛠️ Setup

To get started, clone the repository and navigate to the desired project folder:

git clone https://github.com/Rurutia1027/rust-playground.git
cd rust-playground/

This repository is not project-oriented. Instead, it contains classic Rust examples and small, modular code snippets to demonstrate essential concepts and practical use cases. Each tutorial highlights specific topics: In Tutorial-5 we introduce blockchain-oriented practices and database oriented operations and test cases:

To ensure all test cases executed correctly, we have to deploy a Database of PostgreSQL locally by following steps, then we can make sure the local test cases can be executed successfully.

Database Setup(Tutorial 5 unit test cases rely on)

1. Set Up PostgreSQL Deploy PostgreSQL DB locally or via Docker, and create a PostgreSQL database named defaultdb with the following credentials:

  • username: admin
  • password: admin
  • Dockerfile commands:
docker run --name postgres-db-container \
  -e POSTGRES_USER=admin \
  -e POSTGRES_PASSWORD=admin \
  -e POSTGRES_DB=defaultdb \
  -p 5432:5432 \
  -d postgres

2. Export Database URL as Environment Variable Export the deployed ok database connection URL string as an environment variable so that the test cases can access it. In GitHub CI/CD environment, unit test cases require environment variables that are already declared in each job.

export DATABASE_URL=postgresql://admin:admin@localhost:5432/defaultdb

Run Tests All projects include test cases to verify functionality. All of the test cases should be passed in the local environment and GitHub CI/CD. Use the following command to execute tests in local environments:

cargo test -- --nocapture

The --nocapture flag ensures that println! messages in unit test cases are visible on the console during test execution.


🌟 Features

  • CI/CD Pipeline:
    Continuous integration is set up using GitHub Actions to ensure all projects are built and tested.
    Rust Playground CI Status

  • Hands-On Examples:
    Each tutorial is a standalone project with well-documented code and tests.

  • Learning Focus:
    Tutorials are designed to teach Rust concepts while building meaningful projects.


📝 Contributing

Contributions, discussions, and issues are always welcome! This is not a formal project, but rather a playground for learning and experimenting with Rust. If you have good ideas, suggestions, or want to collaborate, feel free to:

  • Fork the repository, make your changes, and submit a pull request.
  • Open an issue to discuss bugs, improvements, or new ideas.
  • Reach out to me directly via email: [email protected].

Let's learn and build together! 🚀


📚 Resources

Blockchain References

Tutorial Resources

Rust Programming Course

📄 License

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

About

A compact collection of Rust projects for beginners and intermediates. Covers basic syntax, blockchain, distributed systems, and advanced real-world applications like APIs and event handling, with CI/CD integration. Hands-on and practical!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages