help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
rust-web-server
/
src
RSK World
rust-web-server
Rust Web Server - High-Performance Async Web Server + WebSocket Support + JWT Authentication + File Upload + Memory Safety + Educational Design
src
  • auth.rs15.7 KB
  • config.rs2.9 KB
  • error.rs5.2 KB
  • file_upload.rs19 KB
  • handlers.rs12.8 KB
  • lib.rs1.8 KB
  • main.rs6 KB
  • middleware.rs6.2 KB
  • static_files.rs9.9 KB
  • utils.rs9.6 KB
  • websocket.rs15.3 KB
hyperparameter_tuning.cpython-313.pycvalidate_dataset.pyconfig.rslib.rs
src/config.rs
Raw Download
Find: Go to:
/*
 * Configuration Module - Rust Web Server
 * 
 * Created by RSK World (https://rskworld.in)
 * Founder: Molla Samser
 * Designer & Tester: Rima Khatun
 * 
 * Contact:
 * - Email: hello@rskworld.in, support@rskworld.in
 * - Phone: +91 93305 39277
 * - Address: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
 * 
 * © 2026 RSK World. All rights reserved.
 * Content used for educational purposes only.
 */

use serde::{Deserialize, Serialize};
use std::path::PathBuf;

/// Server configuration structure
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServerConfig {
    pub host: String,
    pub port: u16,
    pub static_dir: PathBuf,
    pub workers: usize,
    pub max_connections: usize,
    pub request_timeout_secs: u64,
    pub buffer_size: usize,
}

impl Default for ServerConfig {
    fn default() -> Self {
        Self {
            host: "127.0.0.1".to_string(),
            port: 8080,
            static_dir: PathBuf::from("static"),
            workers: 4,
            max_connections: 1000,
            request_timeout_secs: 30,
            buffer_size: 8192,
        }
    }
}

impl ServerConfig {
    /// Create a new server configuration
    pub fn new(host: String, port: u16, static_dir: PathBuf, workers: usize) -> Self {
        Self {
            host,
            port,
            static_dir,
            workers,
            max_connections: 1000,
            request_timeout_secs: 30,
            buffer_size: 8192,
        }
    }

    /// Get the bind address for the server
    pub fn bind_address(&self) -> String {
        format!("{}:{}", self.host, self.port)
    }

    /// Get the server URL
    pub fn server_url(&self) -> String {
        format!("http://{}", self.bind_address())
    }

    /// Load configuration from file
    pub fn from_file<P: AsRef<std::path::Path>>(path: P) -> Result<Self, Box<dyn std::error::Error>> {
        let content = std::fs::read_to_string(path)?;
        let config: ServerConfig = toml::from_str(&content)?;
        Ok(config)
    }

    /// Save configuration to file
    pub fn to_file<P: AsRef<std::path::Path>>(&self, path: P) -> Result<(), Box<dyn std::error::Error>> {
        let content = toml::to_string_pretty(self)?;
        std::fs::write(path, content)?;
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_default_config() {
        let config = ServerConfig::default();
        assert_eq!(config.host, "127.0.0.1");
        assert_eq!(config.port, 8080);
        assert_eq!(config.workers, 4);
    }

    #[test]
    fn test_bind_address() {
        let config = ServerConfig::new(
            "0.0.0.0".to_string(),
            3000,
            PathBuf::from("public"),
            8,
        );
        assert_eq!(config.bind_address(), "0.0.0.0:3000");
        assert_eq!(config.server_url(), "http://0.0.0.0:3000");
    }
}
109 lines•2.9 KB
rust
src/lib.rs
Raw Download
Find: Go to:
/*
 * Rust Web Server Library
 *
 * Created by RSK World (https://rskworld.in)
 * Founder: Molla Samser
 * Designer & Tester: Rima Khatun
 *
 * Contact:
 * - Email: hello@rskworld.in, support@rskworld.in
 * - Phone: +91 93305 39277
 * - Address: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
 *
 * © 2026 RSK World. All rights reserved.
 * Content used for educational purposes only.
 */

//! # Rust Web Server
//!
//! A high-performance async web server built with Rust, featuring:
//! - Memory safety and thread safety
//! - Async request handling with Tokio
//! - WebSocket support for real-time communication
//! - File upload with validation
//! - JWT-based authentication
//! - Real-time monitoring and metrics
//! - RESTful API endpoints
//! - Static file serving
//!
//! ## Example
//!
//! ```rust,no_run
//! use rust_web_server::config::ServerConfig;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     let config = ServerConfig::default();
//!     // Server implementation would go here
//!     Ok(())
//! }
//! ```

pub mod config;
pub mod error;
pub mod handlers;
pub mod middleware;
pub mod static_files;
pub mod utils;
pub mod auth;
pub mod file_upload;
pub mod websocket;

// Re-export commonly used types
pub use config::ServerConfig;
pub use error::{ServerError, ServerResult};
pub use handlers::SharedState;
pub use static_files::StaticFileHandler;
pub use websocket::WebSocketManager;
pub use file_upload::{FileManager, UploadConfig};
pub use auth::{AuthManager, User, UserRole};

// Version information
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const NAME: &str = env!("CARGO_PKG_NAME");
pub const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
pub const AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
65 lines•1.8 KB
rust
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer