Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
0x0007
1.实现rust代码在线编辑和运行功能
提交
2a4f7b37
1
1.实现rust代码在线编辑和运行功能
项目概览
0x0007
/
1.实现rust代码在线编辑和运行功能
与 Fork 源项目一致
Fork自
inscode / Streamlit
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
1
1.实现rust代码在线编辑和运行功能
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2a4f7b37
编写于
12月 01, 2023
作者:
W
weixin_41863029
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fri Dec 1 16:01:00 CST 2023 inscode
上级
0520122c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
34 addition
and
16 deletion
+34
-16
main.py
main.py
+31
-16
main.rs
main.rs
+3
-0
未找到文件。
main.py
浏览文件 @
2a4f7b37
import
streamlit
as
st
from
streamlit_option_menu
import
option_menu
import
subprocess
# 设置Streamlit应用程序的标题
st
.
set_page_config
(
page_title
=
"app name"
,
layout
=
"wide"
)
st
.
title
(
"Online Rust Compiler"
)
menu1
=
"菜单1"
menu2
=
"菜单2"
code
=
st
.
text_area
(
"Write your rust code here"
,
height
=
300
)
with
st
.
sidebar
:
menu
=
option_menu
(
"菜单"
,
[
menu1
,
menu2
],
icons
=
[
'house'
,
"list-task"
],
menu_icon
=
"cast"
,
default_index
=
0
)
if
st
.
button
(
"Run"
):
st
.
write
(
"Compiling and Running..."
)
def
main
():
with
open
(
"main.rs"
,
"w"
)
as
f
:
f
.
write
(
code
)
if
menu
==
menu1
:
st
.
subheader
(
f
"
{
menu1
}
"
)
compile_process
=
subprocess
.
Popen
(
"rustc main.rs"
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
shell
=
True
)
compile_result
=
compile_process
.
communicate
(
)
if
menu
==
menu2
:
st
.
subheader
(
f
"
{
menu2
}
"
)
if
compile_result
[
1
]:
st
.
write
(
"Compilation Error:"
)
st
.
error
(
compile_result
[
1
].
decode
())
else
:
try
:
run_process
=
subprocess
.
run
(
"./main"
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
shell
=
True
,
timeout
=
10
)
except
subprocess
.
TimeoutExpired
:
st
.
write
(
"Time Limit Exceeded!"
)
st
.
error
(
"Program execution time exceeded 10 seconds."
)
exit
(
0
)
finally
:
with
open
(
"main.rs"
,
"r"
)
as
f
:
code_output
=
f
.
read
()
if
__name__
==
'__main__'
:
main
()
st
.
write
(
"Original Rust Code:"
)
st
.
code
(
code_output
,
language
=
"rust"
)
if
run_process
.
stderr
:
st
.
write
(
"Standard Error:"
)
st
.
error
(
run_process
.
stderr
.
decode
())
if
run_process
.
stdout
:
st
.
write
(
"Standard Output:"
)
st
.
code
(
run_process
.
stdout
.
decode
(),
language
=
"text"
)
\ No newline at end of file
main.rs
0 → 100644
浏览文件 @
2a4f7b37
fn
main
()
{
println!
(
"Hello, world!"
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录