Posts for: #Rust

How to deploy rust app to VPS

Deploying a Rust application to a VPS (Virtual Private Server) involves several key steps. Here’s a comprehensive guide on how to do it:

Prerequisites

  1. Rust Toolchain installed on your local machine (using rustup).
  2. VPS Access: SSH access to the VPS (for example, using SSH keys).
  3. VPS OS: Linux-based OS (Ubuntu, Debian, CentOS, etc.) is assumed.
  4. Cargo (Rust’s package manager and build tool) should be installed on the VPS.
  5. A web server (like Nginx or Apache) for serving HTTP applications (optional, only necessary for web apps).

Step-by-Step Guide

1. Build Your Rust Application

First, build your Rust app for release on your local machine:

Read more

Pengalaman VPS menggunakan DEBIAN 12

DEBIAN adalah distro yang sungguh popular, tetapi kenapa banyak hal yang cukup berbeda dengan UBUNTU yang merupakan salah satunya. Berikut adalah beberapa hal yang cukup berbeda di DEBIAN 12

1. Install rust yang tidak lancar

Jika anda ingin menginstall rust, tidak cukup dengan perintah

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Anda juga harus menambahkan beberapa installasi yang harus dilakukan seperti

sudo apt install build-essential pkg-config libudev-dev libpq-dev

Setelah install itu semua, saya masih tidak bisa melakukan build release aplikasi rust saya.

Read more

Create a REST API with Rust and Connect to Telegram Bot

To create a REST API with Rust that allows you to send photos and videos to a Telegram bot, we can use the Actix Web framework for the API and the Teloxide library for interacting with the Telegram bot.

Steps:

  1. Set up Actix Web to create the REST API.
  2. Use Teloxide to interact with the Telegram API for sending media.
  3. Use multipart form data to handle file uploads in the REST API.

Dependencies:

You will need the following dependencies in Cargo.toml:

Read more

Recommendation Structure Folder For Rust Apps

When organizing a Rust application, it’s important to follow a folder structure that is both maintainable and scalable. A well-organized folder structure makes it easier for developers to understand the code, contribute to the project, and scale the application as it grows. Below is a recommended structure for a typical Rust application, with explanations for each part.

my_rust_app/
├── Cargo.toml                # Project configuration (dependencies, metadata)
├── Cargo.lock                # Lock file (generated after running `cargo build`)
├── src/                      # Source files
│   ├── main.rs               # Main entry point (binary application)
│   ├── lib.rs                # Common library code (if applicable)
│   ├── bin/                  # Additional binaries (optional)
│   ├── models/               # Data models (e.g., structs, enums, etc.)
│   ├── services/             # Business logic / services
│   ├── handlers/             # Request handlers (e.g., for web servers)
│   ├── utils/                # Utility modules (e.g., helpers, utils)
│   ├── db/                   # Database-related code (e.g., migrations, queries)
│   ├── config/               # Configuration and environment setup
│   └── tests/                # Unit and integration tests
├── examples/                 # Example projects or usage demonstrations
├── target/                   # Build output directory (auto-generated by Cargo)
├── tests/                    # Integration tests (optional, alternative to `src/tests`)
├── scripts/                  # Utility scripts (e.g., setup, data generation)
└── README.md                 # Project documentation

Explanation of Folders and Files

1. Cargo.toml & Cargo.lock

  • Cargo.toml: This is the main configuration file for the Rust project. It contains metadata, dependencies, and build configuration for the project.
  • Cargo.lock: This file is automatically generated when you run cargo build or cargo install to lock the dependencies to specific versions. You should commit this file to ensure consistent builds.

2. src/

This folder contains the core source code of the project.

Read more