Kgshop commited on
Commit
e294884
·
verified ·
1 Parent(s): adea619

Update src/main.rs

Browse files
Files changed (1) hide show
  1. 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
- let mut cards_html = String::new();
66
-
67
- for p in PRODUCTS {
68
- cards_html.push_str(&format!(
69
- r#"
70
- <div class="bg-white rounded-2xl shadow-sm hover:shadow-xl transition-shadow duration-300 overflow-hidden border border-gray-100">
71
- <div class="h-48 bg-gray-50 flex items-center justify-center p-6">
72
- <img src="{}" alt="{}" class="max-h-full object-contain">
73
- </div>
74
- <div class="p-6">
75
- <h3 class="text-lg font-bold text-gray-800">{}</h3>
76
- <p class="text-sm text-gray-500 mt-2">{}</p>
77
- <div class="flex items-center justify-between mt-6">
78
- <span class="text-xl font-extrabold text-orange-600">{}</span>
79
- <button class="bg-gray-900 text-white px-4 py-2 rounded-lg hover:bg-orange-600 transition-colors">
80
- В корзину
81
- </button>
82
- </div>
83
  </div>
84
- </div>
85
- "#,
86
- p.image, p.name, p.name, p.description, p.price
87
  ));
88
  }
89
 
90
- // Используем двойные фигурные скобки {{ }} для CSS, чтобы format! их не трогал
91
- let page = format!(
92
- r#"
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 Shop Labs</title>
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 text-gray-900">
106
- <header class="bg-white border-b border-gray-200 sticky top-0 z-50">
107
- <div class="max-w-7xl mx-auto px-4 py-4 flex justify-between items-center">
108
- <div class="flex items-center space-x-2">
109
- <div class="w-10 h-10 bg-orange-600 rounded-lg flex items-center justify-center text-white font-bold text-xl"> R </div>
110
- <span class="text-xl font-extrabold tracking-tight">RUST<span class="text-orange-600">STORE</span></span>
111
- </div>
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
- </header>
125
-
126
- <main class="max-w-7xl mx-auto px-4 py-12">
127
- <div class="text-center mb-16">
128
- <h1 class="text-5xl font-extrabold mb-4">Безопасный шопинг на <span class="text-orange-600">Rust</span></h1>
129
- <p class="text-gray-500 text-lg">Высокая производительность. Нулевая стоимость абстракций.</p>
130
  </div>
131
-
132
- <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
133
- {cards}
134
  </div>
135
  </main>
136
-
137
- <footer class="mt-20 py-10 border-t border-gray-200 text-center text-gray-400 text-sm">
138
- <p>&copy; 2026 Powered by Axum & Rust. HF Spaces Edition.</p>
139
  </footer>
140
  </body>
141
- </html>
142
- "#,
143
- cards = cards_html
144
  );
145
 
146
- AxumHtml(page)
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
+ &copy; 2026 Rust Axum Store | Hugging Face Spaces
 
74
  </footer>
75
  </body>
76
+ </html>"#,
77
+ cards
 
78
  );
79
 
80
+ AxumHtml(html)
81
  }