Update src/main.rs
Browse files- src/main.rs +42 -108
src/main.rs
CHANGED
|
@@ -3,51 +3,10 @@ use axum::{
|
|
| 3 |
routing::get,
|
| 4 |
Router,
|
| 5 |
};
|
| 6 |
-
use serde::Serialize;
|
| 7 |
use std::env;
|
| 8 |
-
use tracing::{info, error};
|
| 9 |
-
|
| 10 |
-
#[derive(Serialize, Clone)]
|
| 11 |
-
struct Product {
|
| 12 |
-
id: u32,
|
| 13 |
-
name: &'static str,
|
| 14 |
-
price: &'static str,
|
| 15 |
-
image: &'static str,
|
| 16 |
-
description: &'static str,
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
const PRODUCTS: &[Product] = &[
|
| 20 |
-
Product {
|
| 21 |
-
id: 1,
|
| 22 |
-
name: "Rust Ferris Plush",
|
| 23 |
-
price: "29.99 $",
|
| 24 |
-
image: "https://rustacean.net/assets/rustacean-flat-gesture.png",
|
| 25 |
-
description: "Мягкий и уютный Феррис для вашего рабочего стола.",
|
| 26 |
-
},
|
| 27 |
-
Product {
|
| 28 |
-
id: 2,
|
| 29 |
-
name: "Turbo Gear",
|
| 30 |
-
price: "49.99 $",
|
| 31 |
-
image: "https://foundation.rust-lang.org/img/rust-logo-blk.svg",
|
| 32 |
-
description: "Шестеренка, которая заставляет всё работать максимально быстро.",
|
| 33 |
-
},
|
| 34 |
-
Product {
|
| 35 |
-
id: 3,
|
| 36 |
-
name: "Memory Safe Shield",
|
| 37 |
-
price: "15.00 $",
|
| 38 |
-
image: "https://www.rust-lang.org/static/images/rust-logo-blk.svg",
|
| 39 |
-
description: "Защита от сегфолтов и утечек памяти в реальной жизни.",
|
| 40 |
-
},
|
| 41 |
-
];
|
| 42 |
|
| 43 |
#[tokio::main]
|
| 44 |
async fn main() {
|
| 45 |
-
tracing_subscriber::fmt()
|
| 46 |
-
.with_max_level(tracing::Level::INFO)
|
| 47 |
-
.init();
|
| 48 |
-
|
| 49 |
-
info!("🚀 Запуск Rust-каталога...");
|
| 50 |
-
|
| 51 |
let app = Router::new()
|
| 52 |
.route("/", get(index_handler))
|
| 53 |
.route("/health", get(|| async { "ok" }));
|
|
@@ -55,93 +14,68 @@ async fn main() {
|
|
| 55 |
let port = env::var("PORT").unwrap_or_else(|_| "7860".to_string());
|
| 56 |
let addr = format!("0.0.0.0:{}", port);
|
| 57 |
|
| 58 |
-
info!("📡 Сервер на {}", addr);
|
| 59 |
-
|
| 60 |
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
| 61 |
axum::serve(listener, app).await.unwrap();
|
| 62 |
}
|
| 63 |
|
| 64 |
async fn index_handler() -> AxumHtml<String> {
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
</div>
|
| 83 |
</div>
|
| 84 |
-
</div>
|
| 85 |
-
|
| 86 |
-
p.image, p.name, p.name, p.description, p.price
|
| 87 |
));
|
| 88 |
}
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
<!DOCTYPE html>
|
| 94 |
-
<html lang="ru">
|
| 95 |
<head>
|
| 96 |
<meta charset="UTF-8">
|
| 97 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 98 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 99 |
-
<title>Rust
|
| 100 |
-
<style>
|
| 101 |
-
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700;800&display=swap');
|
| 102 |
-
body {{ font-family: 'Inter', sans-serif; }}
|
| 103 |
-
</style>
|
| 104 |
</head>
|
| 105 |
-
<body class="bg-gray-50
|
| 106 |
-
<
|
| 107 |
-
<div class="max-w-
|
| 108 |
-
<
|
| 109 |
-
|
| 110 |
-
<
|
| 111 |
-
|
| 112 |
-
<nav class="hidden md:flex space-x-8 font-medium">
|
| 113 |
-
<a href="#" class="hover:text-orange-600">Каталог</a>
|
| 114 |
-
<a href="#" class="hover:text-orange-600">О нас</a>
|
| 115 |
-
<a href="#" class="hover:text-orange-600">Доставка</a>
|
| 116 |
-
</nav>
|
| 117 |
-
<div class="relative p-2">
|
| 118 |
-
<span class="absolute top-0 right-0 bg-orange-600 text-white text-[10px] rounded-full h-4 w-4 flex items-center justify-center"> 0 </span>
|
| 119 |
-
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 120 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 11V7a4 4 0 00-8 0v4M5 9h14l1 12H4L5 9z" />
|
| 121 |
-
</svg>
|
| 122 |
</div>
|
| 123 |
</div>
|
| 124 |
-
</
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
<
|
| 129 |
-
<p class="text-gray-500 text-lg">Высокая производительность. Нулевая стоимость абстракций.</p>
|
| 130 |
</div>
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
{cards}
|
| 134 |
</div>
|
| 135 |
</main>
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
<p>© 2026 Powered by Axum & Rust. HF Spaces Edition.</p>
|
| 139 |
</footer>
|
| 140 |
</body>
|
| 141 |
-
</html>
|
| 142 |
-
|
| 143 |
-
cards = cards_html
|
| 144 |
);
|
| 145 |
|
| 146 |
-
AxumHtml(
|
| 147 |
}
|
|
|
|
| 3 |
routing::get,
|
| 4 |
Router,
|
| 5 |
};
|
|
|
|
| 6 |
use std::env;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
#[tokio::main]
|
| 9 |
async fn main() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
let app = Router::new()
|
| 11 |
.route("/", get(index_handler))
|
| 12 |
.route("/health", get(|| async { "ok" }));
|
|
|
|
| 14 |
let port = env::var("PORT").unwrap_or_else(|_| "7860".to_string());
|
| 15 |
let addr = format!("0.0.0.0:{}", port);
|
| 16 |
|
|
|
|
|
|
|
| 17 |
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
| 18 |
axum::serve(listener, app).await.unwrap();
|
| 19 |
}
|
| 20 |
|
| 21 |
async fn index_handler() -> AxumHtml<String> {
|
| 22 |
+
// Список товаров
|
| 23 |
+
let products = vec![
|
| 24 |
+
("Rust Ferris", "29.99 $", "https://rustacean.net/assets/rustacean-flat-gesture.png", "Мягкий краб Феррис."),
|
| 25 |
+
("Turbo Engine", "49.99 $", "https://foundation.rust-lang.org/img/rust-logo-blk.svg", "Максимальная скорость."),
|
| 26 |
+
("Safe Shield", "15.00 $", "https://www.rust-lang.org/static/images/rust-logo-blk.svg", "Безопасность памяти."),
|
| 27 |
+
];
|
| 28 |
+
|
| 29 |
+
let mut cards = String::new();
|
| 30 |
+
for p in products {
|
| 31 |
+
cards.push_str(&format!(
|
| 32 |
+
r#"<div class="bg-white rounded-xl shadow-md overflow-hidden border border-gray-100 p-4">
|
| 33 |
+
<img src="{}" class="h-40 w-full object-contain mb-4">
|
| 34 |
+
<h3 class="text-lg font-bold">{}</h3>
|
| 35 |
+
<p class="text-sm text-gray-500 mb-4">{}</p>
|
| 36 |
+
<div class="flex justify-between items-center">
|
| 37 |
+
<span class="text-orange-600 font-bold text-xl">{}</span>
|
| 38 |
+
<button class="bg-black text-white px-3 py-1 rounded shadow hover:bg-orange-600 transition">Купить</button>
|
|
|
|
| 39 |
</div>
|
| 40 |
+
</div>"#,
|
| 41 |
+
p.2, p.0, p.3, p.1
|
|
|
|
| 42 |
));
|
| 43 |
}
|
| 44 |
|
| 45 |
+
let html = format!(
|
| 46 |
+
r#"<!DOCTYPE html>
|
| 47 |
+
<html>
|
|
|
|
|
|
|
| 48 |
<head>
|
| 49 |
<meta charset="UTF-8">
|
|
|
|
| 50 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 51 |
+
<title>Rust Store</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
</head>
|
| 53 |
+
<body class="bg-gray-50 font-sans">
|
| 54 |
+
<nav class="bg-white shadow-sm p-4 sticky top-0 z-10">
|
| 55 |
+
<div class="max-w-6xl mx-auto flex justify-between items-center">
|
| 56 |
+
<h1 class="text-2xl font-black text-orange-600 tracking-tighter">RUST SHOP</h1>
|
| 57 |
+
<div class="space-x-4 text-gray-600 font-medium">
|
| 58 |
+
<a href="#">Каталог</a>
|
| 59 |
+
<a href="#">Доставка</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
</div>
|
| 61 |
</div>
|
| 62 |
+
</nav>
|
| 63 |
+
<main class="max-w-6xl mx-auto p-8">
|
| 64 |
+
<div class="mb-12 text-center">
|
| 65 |
+
<h2 class="text-4xl font-extrabold text-gray-900 mb-2">Надежный мерч на Rust</h2>
|
| 66 |
+
<p class="text-gray-500">Скомпилировано для вашего комфорта</p>
|
|
|
|
| 67 |
</div>
|
| 68 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
|
| 69 |
+
{}
|
|
|
|
| 70 |
</div>
|
| 71 |
</main>
|
| 72 |
+
<footer class="text-center py-10 text-gray-400 text-sm border-t mt-10">
|
| 73 |
+
© 2026 Rust Axum Store | Hugging Face Spaces
|
|
|
|
| 74 |
</footer>
|
| 75 |
</body>
|
| 76 |
+
</html>"#,
|
| 77 |
+
cards
|
|
|
|
| 78 |
);
|
| 79 |
|
| 80 |
+
AxumHtml(html)
|
| 81 |
}
|