Struct hyper_scripter::script_type::ScriptType
source · pub struct ScriptType(_);Implementations§
source§impl ScriptType
impl ScriptType
sourcepub fn new_unchecked(s: String) -> Self
pub fn new_unchecked(s: String) -> Self
Examples found in repository?
src/script_repo/mod.rs (line 377)
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
pub async fn new(
recent: Option<RecentFilter>,
db_env: DBEnv,
selector: &TagSelectorGroup,
) -> Result<ScriptRepo> {
let mut hidden_map = HashMap::<String, ScriptInfo>::default();
let mut map: HashMap<String, ScriptInfo> = Default::default();
let time_bound = recent.map(|r| {
let mut time = Utc::now().naive_utc();
time -= Duration::days(r.recent.into());
(time, r.archaeology)
});
let scripts = sqlx::query!(
"SELECT * FROM script_infos si LEFT JOIN last_events le ON si.id = le.script_id"
)
.fetch_all(&db_env.info_pool)
.await?;
for record in scripts.into_iter() {
let name = record.name;
log::trace!("載入腳本:{} {} {}", name, record.ty, record.tags);
let script_name = name.clone().into_script_name_unchecked()?; // NOTE: 從資料庫撈出來就別檢查了吧
let mut builder = ScriptInfo::builder(
record.id,
script_name,
ScriptType::new_unchecked(record.ty),
record.tags.split(',').filter_map(|s| {
if s.is_empty() {
None
} else {
Some(Tag::new_unchecked(s.to_string()))
}
}),
);
builder.created_time(record.created_time);
if let Some(count) = record.exec_count {
builder.exec_count(count as u64);
}
if let Some(time) = record.write {
builder.write_time(time);
}
if let Some(time) = record.read {
builder.read_time(time);
}
if let Some(time) = record.miss {
builder.miss_time(time);
}
if let Some(time) = record.exec {
builder.exec_time(time);
}
if let Some(time) = record.exec_done {
builder.exec_done_time(time);
}
if let Some(time) = record.neglect {
builder.neglect_time(time);
}
if let Some(time) = record.humble {
builder.humble_time(time);
}
let script = builder.build();
let mut hide = false;
if let Some((mut time_bound, archaeology)) = time_bound {
if let Some(neglect) = record.neglect {
log::debug!("腳本 {} 曾於 {} 被忽略", script.name, neglect);
time_bound = std::cmp::max(neglect, time_bound);
}
let overtime = time_bound > script.last_major_time();
hide = archaeology ^ overtime
}
if !hide {
hide = !selector.select(&script.tags, &script.ty);
}
if hide {
hidden_map.insert(name, script);
} else {
log::trace!("腳本 {:?} 通過篩選", name);
map.insert(name, script);
}
}
Ok(ScriptRepo {
map,
hidden_map,
latest_name: None,
db_env,
})
}Trait Implementations§
source§impl AsRef<str> for ScriptType
impl AsRef<str> for ScriptType
source§impl Clone for ScriptType
impl Clone for ScriptType
source§fn clone(&self) -> ScriptType
fn clone(&self) -> ScriptType
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for ScriptType
impl Debug for ScriptType
source§impl Default for ScriptType
impl Default for ScriptType
source§impl<'de> Deserialize<'de> for ScriptType
impl<'de> Deserialize<'de> for ScriptType
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Display for ScriptType
impl Display for ScriptType
source§impl FromStr for ScriptType
impl FromStr for ScriptType
§type Err = DisplayError
type Err = DisplayError
The associated error which can be returned from parsing.
source§impl Hash for ScriptType
impl Hash for ScriptType
source§impl PartialEq<ScriptType> for ScriptType
impl PartialEq<ScriptType> for ScriptType
source§fn eq(&self, other: &ScriptType) -> bool
fn eq(&self, other: &ScriptType) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl Serialize for ScriptType
impl Serialize for ScriptType
impl Eq for ScriptType
impl StructuralEq for ScriptType
impl StructuralPartialEq for ScriptType
Auto Trait Implementations§
impl RefUnwindSafe for ScriptType
impl Send for ScriptType
impl Sync for ScriptType
impl Unpin for ScriptType
impl UnwindSafe for ScriptType
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.