Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit87bfd9b

Browse files
committed
runtime: reduce visual clutter by removing type annotations
This makes the logic pop out easily to the reader.
1 parent0881285 commit87bfd9b

File tree

10 files changed

+83
-110
lines changed

10 files changed

+83
-110
lines changed

‎src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,18 @@ macro_rules! collect_test {
141141
#[macro_export]
142142
macro_rules! dump_test{
143143
($vec:ident) =>{{
144-
letmutnfailed:usize =0;
144+
letmutnum_failed =0;
145145
// Dump results.
146146
for(test_name, test_status, test_result) in $vec{
147147
std::println!("[{}] {}", test_status, test_name);
148148
ifletErr(e) = test_result{
149-
nfailed +=1;
149+
num_failed +=1;
150150
std::println!("{}", e);
151151
}
152152
}
153153

154-
ifnfailed >0{
155-
anyhow::bail!("{} tests failed",nfailed);
154+
ifnum_failed >0{
155+
anyhow::bail!("{} tests failed",num_failed);
156156
} else{
157157
std::println!("all tests passed");
158158
Ok(())

‎src/runtime/condition_variable.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ pub struct ConditionVariable {
4747
pubstructSharedConditionVariable(SharedObject<ConditionVariable>);
4848

4949
structYieldPoint{
50-
/// Unique identifier.
5150
id:YieldPointId,
52-
/// Reference to the condition variable that issued this future.
53-
cond_var:SharedConditionVariable,
54-
/// State of the yield.
51+
/// Condition variable that issued this future.
52+
condition_variable:SharedConditionVariable,
5553
state:YieldState,
5654
}
5755

@@ -88,7 +86,7 @@ impl SharedConditionVariable {
8886
self.last_id +=1;
8987
YieldPoint{
9088
id:YieldPointId(self.last_id),
91-
cond_var:self.clone(),
89+
condition_variable:self.clone(),
9290
state:YieldState::Running,
9391
}
9492
.await
@@ -137,17 +135,17 @@ impl Future for YieldPoint {
137135
/// The first time that this future is polled, it is not ready but the next time must be a signal so then it is
138136
/// ready.
139137
fnpoll(self:Pin<&mutSelf>,context:&mutContext) ->Poll<Self::Output>{
140-
let state:YieldState =self.state;
141-
let num_ready:usize=self.cond_var.num_ready;
142-
let self_:&mutSelf =self.get_mut();
138+
let state =self.state;
139+
let num_ready=self.condition_variable.num_ready;
140+
let self_ =self.get_mut();
143141
match state{
144142
YieldState::Running =>{
145-
self_.cond_var.add_waiter(self_.id, context.waker().clone());
143+
self_.condition_variable.add_waiter(self_.id, context.waker().clone());
146144
self_.state =YieldState::Yielded;
147145
Poll::Pending
148146
},
149147
YieldState::Yieldedif num_ready >0 =>{
150-
self_.cond_var.num_ready -=1;
148+
self_.condition_variable.num_ready -=1;
151149
self_.state =YieldState::Running;
152150
Poll::Ready(())
153151
},
@@ -158,7 +156,7 @@ impl Future for YieldPoint {
158156

159157
implDropforYieldPoint{
160158
fndrop(&mutself){
161-
self.cond_var.remove_waiter(self.id)
159+
self.condition_variable.remove_waiter(self.id)
162160
}
163161
}
164162

‎src/runtime/fail.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,17 @@ use ::std::{error, fmt, io};
1212
// Structures
1313
//======================================================================================================================
1414

15-
/// Failure
1615
#[derive(Clone)]
1716
pubstructFail{
18-
/// Error code.
1917
puberrno:c_int,
20-
/// Cause.
2118
pubcause:String,
2219
}
2320

2421
//======================================================================================================================
2522
// Associate Functions
2623
//======================================================================================================================
2724

28-
/// Associate Functions for Failures
2925
implFail{
30-
/// Creates a new Failure
3126
pubfnnew(errno:i32,cause:&str) ->Self{
3227
Self{
3328
errno,
@@ -40,24 +35,20 @@ impl Fail {
4035
// Trait Implementations
4136
//======================================================================================================================
4237

43-
/// Display Trait Implementation for Failures
4438
impl fmt::DisplayforFail{
4539
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
4640
write!(f,"Error {:?}: {:?}",self.errno,self.cause)
4741
}
4842
}
4943

50-
/// Debug trait Implementation for Failures
5144
impl fmt::DebugforFail{
5245
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
5346
write!(f,"Error {:?}: {:?}",self.errno,self.cause)
5447
}
5548
}
5649

57-
/// Error Trait Implementation for Failures
5850
impl error::ErrorforFail{}
5951

60-
/// Conversion Trait Implementation for Fail
6152
implFrom<io::Error>forFail{
6253
fnfrom(_: io::Error) ->Self{
6354
Self{

‎src/runtime/logging.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub struct CallbackLogWriter {
2929
// Associated Functions
3030
//=====================================================================================================================
3131
implCallbackLogWriter{
32-
/// Creates a new `CallbackLogWriter` instance.
3332
pubfnnew(callback:demi_log_callback_t) ->Self{
3433
Self{ callback}
3534
}
@@ -40,9 +39,9 @@ impl CallbackLogWriter {
4039
//======================================================================================================================
4140
implLogWriterforCallbackLogWriter{
4241
fnwrite(&self,_now:&mut flexi_logger::DeferredNow,record:&log::Record) -> std::io::Result<()>{
43-
let module:&str = record.module_path().unwrap_or("{unnamed}");
44-
let file:&str = record.file().unwrap_or("{unknown file}");
45-
let message:String = record.args().to_string();
42+
let module = record.module_path().unwrap_or("{unnamed}");
43+
let file = record.file().unwrap_or("{unknown file}");
44+
let message = record.args().to_string();
4645
((self.callback)(
4746
record.level()asi32,
4847
module.as_ptr()as*const std::ffi::c_char,
@@ -66,7 +65,6 @@ impl LogWriter for CallbackLogWriter {
6665
// Standalone Functions
6766
//======================================================================================================================
6867

69-
/// Initializes logging features.
7068
pubfninitialize(){
7169
let _ =LOG_HANDLE.get_or_init(||Logger::try_with_env().unwrap().format(with_thread).start().unwrap());
7270
}
@@ -77,7 +75,7 @@ pub fn initialize() {
7775
#[allow(unused)]
7876
pubfncustom_initialize<F:FnOnce() ->Logger>(f:F){
7977
let _ =LOG_HANDLE.get_or_init(||{
80-
let logger:Logger =f();
78+
let logger =f();
8179
logger.start().unwrap()
8280
});
8381
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp