mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: reorder bugs
This commit is contained in:
@ -1,8 +1,4 @@
|
||||
pub mod code_gen;
|
||||
pub mod future;
|
||||
pub mod retry;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn timestamp() -> i64 {
|
||||
chrono::Utc::now().timestamp()
|
||||
}
|
||||
pub mod util;
|
||||
|
32
shared-lib/lib-infra/src/util.rs
Normal file
32
shared-lib/lib-infra/src/util.rs
Normal file
@ -0,0 +1,32 @@
|
||||
pub fn move_vec_element<T, F>(
|
||||
vec: &mut Vec<T>,
|
||||
filter: F,
|
||||
_from_index: usize,
|
||||
mut to_index: usize,
|
||||
) -> Result<bool, String>
|
||||
where
|
||||
F: FnMut(&T) -> bool,
|
||||
{
|
||||
match vec.iter().position(filter) {
|
||||
None => Ok(false),
|
||||
Some(index) => {
|
||||
if vec.len() > to_index {
|
||||
let removed_element = vec.remove(index);
|
||||
vec.insert(to_index, removed_element);
|
||||
Ok(true)
|
||||
} else {
|
||||
let msg = format!(
|
||||
"Move element to invalid index: {}, current len: {}",
|
||||
to_index,
|
||||
vec.len()
|
||||
);
|
||||
Err(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn timestamp() -> i64 {
|
||||
chrono::Utc::now().timestamp()
|
||||
}
|
Reference in New Issue
Block a user