Skip to content

Commit 2ef9413

Browse files
committed
refactor(add_test_case): delete unsafe code
1 parent 5228ae3 commit 2ef9413

File tree

4 files changed

+53
-84
lines changed

4 files changed

+53
-84
lines changed

Cargo.lock

+44-65
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/lcode/src/app/edit/cmds/submit.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ pub struct SubmitState {
1616
pub row_len: usize,
1717

1818
pub need_add_test_case: bool,
19-
20-
pub add_case_handle: Option<tokio::task::JoinHandle<()>>,
2119
}
2220

2321
impl SubmitState {

crates/lcode/src/app/inner.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,20 @@ impl<'app_lf> App<'app_lf> {
4949
.parse()
5050
.expect("submit res question id parse error");
5151

52-
// SAFETY: `last_testcase` field can live on whole app
53-
let case: &'static str = unsafe {
54-
std::mem::transmute(
55-
self.edit
56-
.submit
57-
.content
58-
.last_testcase
59-
.as_str(),
60-
)
61-
};
62-
let hd = tokio::spawn(async move {
52+
let case = self
53+
.edit
54+
.submit
55+
.content
56+
.last_testcase
57+
.clone();
58+
59+
tokio::spawn(async move {
6360
glob_leetcode()
6461
.await
65-
.add_test_case(id, case)
62+
.add_test_case(id, &case)
6663
.await
6764
.ok();
6865
});
69-
self.edit.submit.add_case_handle = Some(hd);
7066
self.edit.submit.not_need_add();
7167

7268
true

crates/lcode/src/mytui/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ pub async fn run() -> Result<()> {
3131
},
3232
UserEvent::UserInfo(info) => app.get_status_done(*info),
3333
UserEvent::SubmitDone(s_res) => {
34-
if let Some(hd) = app.edit.submit.add_case_handle.take() {
35-
// abort add test case, because last test case may change
36-
hd.abort();
37-
}
3834
// update info
3935
if s_res.total_correct == s_res.total_testcases {
4036
app.user_info_and_checkin();

0 commit comments

Comments
 (0)