Code Guideline

This guide outlines the recommended code guideline in Mega project.


Comment

This guide outlines the recommended order for importing dependencies in Rust projects.

### File Header Comments (//!)

### Struct Comments (///)

### Function Comments (///)

Rust Dependency Import Order

This guide outlines the recommended order for importing dependencies in Rust projects.

  1. Rust Standard Library

Import dependencies from the Rust standard library.

  1. Third-Party Crates

Import dependencies from third-party crates.

  1. Other Modules in Workspace

Import dependencies from other modules within the project workspace.

  1. Within Modules

Import functions and structs from within modules.

Example:


// 1. Rust Standard Library
use std::collections::HashMap;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::{Arc, Mutex};

// 2. Third-Party Crates
use bytes::{BufMut, Bytes, BytesMut};
use russh::server::{self, Auth, Msg, Session};
use russh::{Channel, ChannelId};
use russh_keys::key;
use tokio::io::{AsyncReadExt, BufReader};

// 3. Other Modules in Workspace
use storage::driver::database::storage::ObjectStorage;

// 4. Other Files in the Same Module
use crate::protocol::pack::{self};
use crate::protocol::ServiceType;
use crate::protocol::{PackProtocol, Protocol};

Additional Notes:

  • Always group imports with an empty line between different sections for better readability.
  • Alphabetize imports within each section to maintain consistency.
  • Avoid using extern crate syntax for Rust 2018 edition and later; prefer using use with crates.
  • Do not use super:: and self:: in imports. It can lead to ambiguity and hinder code readability. Instead, use crate to reference the current crate's modules.