Struct hyper_scripter::state::State
source · pub struct State<T> { /* private fields */ }Implementations§
source§impl<T: Sized> State<T>
impl<T: Sized> State<T>
sourcepub const fn new() -> State<T>
pub const fn new() -> State<T>
Examples found in repository?
More examples
sourcepub fn set(&self, data: T)
pub fn set(&self, data: T)
Examples found in repository?
More examples
sourcepub fn get(&self) -> &T
pub fn get(&self) -> &T
Examples found in repository?
More examples
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
}