Struct hyper_scripter::state::State

source ·
pub struct State<T> { /* private fields */ }

Implementations§

Examples found in repository?
src/path.rs (line 21)
21
static PATH: State<PathBuf> = State::new();
More examples
Hide additional examples
src/config.rs (line 18)
18
19
static CONFIG: State<Config> = State::new();
static PROMPT_LEVEL: State<PromptLevel> = State::new();
src/list/time_fmt.rs (line 5)
5
static NOW: State<NaiveDateTime> = State::new();
src/fuzzy.rs (line 55)
55
static MATCHER: State<SkimMatcherV2> = State::new();

不論是否為測試中,強制設定狀態

Examples found in repository?
src/list/time_fmt.rs (line 9)
7
8
9
10
pub fn init() {
    let now = Utc::now().naive_local();
    NOW.set(now);
}
More examples
Hide additional examples
src/config.rs (line 222)
221
222
223
224
225
226
227
228
229
230
    pub fn init() -> Result {
        CONFIG.set(Config::load(path::get_home())?);
        Ok(())
    }

    pub fn set_prompt_level(l: Option<PromptLevel>) {
        let c = Config::get();
        let l = l.unwrap_or(c.prompt_level); // TODO: 測試由設定檔設定 prompt-level 的情境?
        PROMPT_LEVEL.set(l);
    }
src/path.rs (line 122)
120
121
122
123
124
pub fn set_home<T: AsRef<Path>>(p: Option<T>, create_on_missing: bool) -> Result {
    let path = compute_home_path_optional(p, create_on_missing)?;
    PATH.set(path);
    Ok(())
}
Examples found in repository?
src/path.rs (line 128)
127
128
129
pub fn get_home() -> &'static Path {
    PATH.get().as_ref()
}
More examples
Hide additional examples
src/config.rs (line 232)
231
232
233
234
235
236
237
238
    pub fn get_prompt_level() -> PromptLevel {
        *PROMPT_LEVEL.get()
    }

    #[cfg(not(test))]
    pub fn get() -> &'static Config {
        CONFIG.get()
    }
src/list/time_fmt.rs (line 15)
13
14
15
16
17
18
19
20
21
22
23
24
pub fn fmt<T>(time: &ScriptTime<T>) -> String {
    let time = Local.from_utc_datetime(&**time).naive_local();
    let now = NOW.get();

    if now.date() == time.date() {
        format!("{}", time.format("%H:%M"))
    } else if now.year() == time.year() {
        format!("{}", time.format("%d %b"))
    } else {
        format!("{}", time.format("%Y"))
    }
}
src/fuzzy.rs (line 259)
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
fn my_fuzz(choice: &str, pattern: &str, sep: &str, boost_exact: bool) -> Option<i64> {
    if boost_exact && choice == pattern {
        return Some(EXACXT_SCORE);
    }
    let mut ans_opt = None;
    let mut first = true;
    foreach_reorder(choice, sep, &mut |choice_reordered| {
        let score_opt = MATCHER.get().fuzzy_match(choice_reordered, pattern);
        log::trace!(
            "模糊搜尋,候選者:{},重排列成:{},輸入:{},分數:{:?}",
            choice,
            choice_reordered,
            pattern,
            score_opt,
        );
        if let Some(mut score) = score_opt {
            if first {
                // NOTE: 正常排序的分數會稍微高一點
                // 例如 [a/b, b/a] 中要找 `a/b`,則前者以分毫之差勝出
                score += 1;
                log::trace!(
                    "模糊搜尋,候選者:{},正常排序就命中,分數略提升為 {}",
                    choice,
                    score
                );
            }
            if let Some(ans) = ans_opt {
                ans_opt = Some(std::cmp::max(score, ans));
            } else {
                ans_opt = Some(score);
            }
        }
        first = false;
    });
    ans_opt
}

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.