Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ CodeForge 是一款轻量级、高性能的桌面代码执行器,专为开发
- **Node.js**
- **Go**
- **Java**
- **Shell**
- **Rust**
- **...更多语言敬请期待**

## 安装
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@codemirror/lang-java": "^6.0.2",
"@codemirror/lang-javascript": "^6.2.4",
"@codemirror/lang-python": "^6.2.1",
"@codemirror/lang-rust": "^6.0.2",
"@codemirror/language": "^6.11.2",
"@codemirror/legacy-modes": "^6.5.1",
"@codemirror/state": "^6.5.2",
Expand Down
3 changes: 3 additions & 0 deletions public/icons/rust.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src-tauri/src/plugins/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::{
python3::Python3Plugin,
};
use crate::plugins::java::JavaPlugin;
use crate::plugins::rust::RustPlugin;
use crate::plugins::shell::ShellPlugin;
use std::collections::HashMap;

Expand All @@ -20,6 +21,7 @@ impl PluginManager {
plugins.insert("go".to_string(), Box::new(GoPlugin));
plugins.insert("java".to_string(), Box::new(JavaPlugin));
plugins.insert("shell".to_string(), Box::new(ShellPlugin));
plugins.insert("rust".to_string(), Box::new(RustPlugin));

Self { plugins }
}
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ pub mod manager;
pub mod nodejs;
pub mod python2;
pub mod python3;
pub mod rust;
pub mod shell;

pub use manager::PluginManager;
67 changes: 67 additions & 0 deletions src-tauri/src/plugins/rust.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use super::{LanguagePlugin, PluginConfig};
use std::vec;

pub struct RustPlugin;

impl LanguagePlugin for RustPlugin {
fn get_order(&self) -> i32 {
7
}

fn get_language_name(&self) -> &'static str {
"Rust"
}

fn get_language_key(&self) -> &'static str {
"rust"
}

fn get_file_extension(&self) -> String {
self.get_config()
.map(|config| config.extension.clone())
.unwrap_or_else(|| "rs".to_string())
}

fn get_version_args(&self) -> Vec<&'static str> {
vec!["--version"]
}

fn get_path_command(&self) -> String {
"rustc --print sysroot".to_string()
}

fn get_execute_args(&self, file_path: &str) -> Vec<String> {
let cmd = if self.get_execute_home().is_some() {
format!("./rustc {} -o ./main && ./main", file_path)
} else {
format!(
"export PATH=$PATH:$HOME/.cargo/bin && rustc {} -o /tmp/main && /tmp/main",
file_path
)
};

vec!["-c".to_string(), cmd]
}

fn get_default_config(&self) -> PluginConfig {
PluginConfig {
enabled: true,
language: String::from("rust"),
before_compile: None,
extension: String::from("rs"),
execute_home: None,
run_command: Some(String::from("bash")),
after_compile: Some(String::from("rm -f /tmp/main")),
template: Some(String::from(
"// Rust 示例代码 - CodeForge 代码执行环境\n\nfn main() {\n println!(\"🎉 欢迎使用 CodeForge!\");\n println!(\"Welcome to CodeForge!\");\n println!(\"\");\n \n println!(\"=========================================\");\n println!(\" CodeForge Rust \");\n println!(\"=========================================\");\n println!(\"\");\n \n // 基本输出示例\n println!(\"✅ Rust 运行成功! (Rust is working!)\");\n println!(\"🦀 这是 Rust 版本 (This is Rust)\");\n println!(\"\");\n \n // 简单计算\n let number1 = 10;\n let number2 = 20;\n let result = number1 + number2;\n \n println!(\"🔢 简单计算 (Simple calculation):\");\n println!(\"{} + {} = {}\", number1, number2, result);\n println!(\"\");\n \n // 字符串操作\n let name = \"CodeForge\";\n let version = \"Rust\";\n \n println!(\"📝 字符串操作 (String operations):\");\n println!(\"平台名称 (Platform): {}\", name);\n println!(\"语言版本 (Language): {}\", version);\n println!(\"完整信息 (Full info): {} - {}\", name, version);\n println!(\"\");\n \n // 循环示例\n println!(\"🔄 循环输出 (Loop output):\");\n for i in 1..=5 {\n println!(\"第 {} 次输出 (Output #{}): Hello from CodeForge!\", i, i);\n }\n println!(\"\");\n \n // 向量操作\n let fruits = vec![\"苹果\", \"香蕉\", \"橙子\", \"葡萄\"];\n println!(\"🍎 水果列表 (Fruit list):\");\n for (index, fruit) in fruits.iter().enumerate() {\n println!(\"{}. {}\", index + 1, fruit);\n }\n println!(\"\");\n \n // 条件判断\n let score = 85;\n println!(\"📊 成绩评估 (Score evaluation):\");\n if score >= 90 {\n println!(\"优秀! (Excellent!)\");\n } else if score >= 80 {\n println!(\"良好! (Good!)\");\n } else if score >= 60 {\n println!(\"及格 (Pass)\");\n } else {\n println!(\"需要努力 (Need improvement)\");\n }\n \n // Rust 特有的所有权演示\n println!(\"\");\n println!(\"🔒 Rust 所有权演示 (Ownership demonstration):\");\n let mut message = String::from(\"Hello\");\n message.push_str(\", CodeForge!\");\n println!(\"可变字符串 (Mutable string): {}\", message);\n \n // Option 类型演示\n let maybe_number: Option<i32> = Some(42);\n match maybe_number {\n Some(n) => println!(\"找到数字 (Found number): {}\", n),\n None => println!(\"没有数字 (No number)\"),\n }\n \n println!(\"\");\n println!(\"🎯 CodeForge Rust 代码执行完成!\");\n println!(\"🎯 CodeForge Rust execution completed!\");\n println!(\"\");\n println!(\"感谢使用 CodeForge 代码执行环境! 🚀\");\n println!(\"Thank you for using CodeForge! 🚀\");\n}",
)),
timeout: Some(30),
}
}

fn get_default_command(&self) -> String {
self.get_config()
.and_then(|config| config.run_command.clone())
.unwrap_or_else(|| "/tmp/main".to_string())
}
}
3 changes: 3 additions & 0 deletions src/composables/useCodeMirrorEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { python } from '@codemirror/lang-python'
import { javascript } from '@codemirror/lang-javascript'
import { go } from '@codemirror/lang-go'
import { java } from '@codemirror/lang-java'
import { rust } from '@codemirror/lang-rust'
import { shell } from '@codemirror/legacy-modes/mode/shell'
import {
abcdef,
Expand Down Expand Up @@ -155,6 +156,8 @@ export function useCodeMirrorEditor(props: Props)
return go()
case 'java':
return java()
case 'rust':
return rust()
case 'shell':
return StreamLanguage.define(shell)
default:
Expand Down
Loading