mirror of
https://git.intege.rs/xlib/x.git
synced 2025-12-06 04:45:02 +00:00
ondrop
This commit is contained in:
@@ -18,3 +18,23 @@ macro_rules! invoke_once {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct OnDrop<F: FnOnce()>(Option<F>);
|
||||||
|
|
||||||
|
impl<F: FnOnce()> OnDrop<F> {
|
||||||
|
pub fn new(fun: F) -> Self {
|
||||||
|
Self(Some(fun))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<F: FnOnce()> Drop for OnDrop<F> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
if let Some(fun) = self.0.take() {
|
||||||
|
fun()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ pub const fn hash32(bytes: &[u32]) -> u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//noinspection DuplicatedCode
|
//noinspection DuplicatedCode
|
||||||
|
#[inline(always)]
|
||||||
pub const fn hash64(bytes: &[u64]) -> u64 {
|
pub const fn hash64(bytes: &[u64]) -> u64 {
|
||||||
let mut hash = INITIAL_STATE;
|
let mut hash = INITIAL_STATE;
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
@@ -38,6 +39,7 @@ pub const fn hash64(bytes: &[u64]) -> u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//noinspection DuplicatedCode
|
//noinspection DuplicatedCode
|
||||||
|
#[inline(always)]
|
||||||
pub const fn hash_utf8(bytes: &[u8]) -> u64 {
|
pub const fn hash_utf8(bytes: &[u8]) -> u64 {
|
||||||
let mut hash = INITIAL_STATE;
|
let mut hash = INITIAL_STATE;
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user