diff options
Diffstat (limited to 'systems')
| -rw-r--r-- | systems/_asset/src/asset.rs | 37 | ||||
| -rw-r--r-- | systems/_asset/src/rw.rs | 16 | ||||
| -rw-r--r-- | systems/_asset/test/src/lib.rs | 12 | ||||
| -rw-r--r-- | systems/_constants/macros/src/lib.rs | 34 | ||||
| -rw-r--r-- | systems/_framework/src/space.rs | 16 | ||||
| -rw-r--r-- | systems/sheet/macros/src/lib.rs | 4 | ||||
| -rw-r--r-- | systems/sheet/src/compare.rs | 2 | ||||
| -rw-r--r-- | systems/sheet/src/index_source.rs | 10 | ||||
| -rw-r--r-- | systems/sheet/src/index_source/alias.rs | 15 | ||||
| -rw-r--r-- | systems/sheet/src/lazy.rs | 4 | ||||
| -rw-r--r-- | systems/sheet/src/mapping.rs | 32 | ||||
| -rw-r--r-- | systems/sheet/src/mapping/parse.rs | 4 | ||||
| -rw-r--r-- | systems/sheet/src/sheet.rs | 29 | ||||
| -rw-r--r-- | systems/sheet/src/sheet/v1/constants.rs | 12 | ||||
| -rw-r--r-- | systems/sheet/src/sheet/v1/writer.rs | 9 | ||||
| -rw-r--r-- | systems/vault/src/vault/config.rs | 20 | ||||
| -rw-r--r-- | systems/vault/src/vault/manager.rs | 6 | ||||
| -rw-r--r-- | systems/workspace/src/workspace/config.rs | 20 | ||||
| -rw-r--r-- | systems/workspace/src/workspace/manager.rs | 6 | ||||
| -rw-r--r-- | systems/workspace/src/workspace/manager/id_aliases.rs | 6 | ||||
| -rw-r--r-- | systems/workspace/src/workspace/manager/sheet_state.rs | 15 |
21 files changed, 135 insertions, 174 deletions
diff --git a/systems/_asset/src/asset.rs b/systems/_asset/src/asset.rs index c2b75e6..f452e2b 100644 --- a/systems/_asset/src/asset.rs +++ b/systems/_asset/src/asset.rs @@ -99,21 +99,17 @@ where .open(&lock_path) .await { - Ok(_) => { - return Ok(Handle { - _data_type: PhantomData, - writed: false, - asset_path: self.path.clone(), - lock_path, - temp_path, - }); - } + Ok(_) => Ok(Handle { + _data_type: PhantomData, + writed: false, + asset_path: self.path.clone(), + lock_path, + temp_path, + }), Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => { - return Err(HandleLockError::AssetLocked); - } - Err(e) => { - return Err(HandleLockError::IoError(e)); + Err(HandleLockError::AssetLocked) } + Err(e) => Err(HandleLockError::IoError(e)), } } @@ -231,7 +227,7 @@ where if self.writed { tokio::fs::rename(&from, &to) .await - .map_err(|e| DataApplyError::IoError(e))?; + .map_err(DataApplyError::IoError)?; } Ok(()) } @@ -350,18 +346,15 @@ async fn check_asset_path<D>(handle: &Handle<D>) -> Result<(), PrecheckFailed> where D: RWData<D>, { - if let Some(file_name) = handle.asset_path.file_name() { - if check_path(file_name).is_ok() { - return Ok(()); - } + if let Some(file_name) = handle.asset_path.file_name() + && check_path(file_name).is_ok() + { + return Ok(()); } Err(PrecheckFailed::AssetPathInvalid) } -async fn check_handle_is_cross_directory( - from: &PathBuf, - to: &PathBuf, -) -> Result<(), PrecheckFailed> { +async fn check_handle_is_cross_directory(from: &Path, to: &Path) -> Result<(), PrecheckFailed> { let from_parent = from.parent(); let to_parent = to.parent(); diff --git a/systems/_asset/src/rw.rs b/systems/_asset/src/rw.rs index 9a46144..7595138 100644 --- a/systems/_asset/src/rw.rs +++ b/systems/_asset/src/rw.rs @@ -1,17 +1,17 @@ -use std::path::PathBuf; +use std::path::Path; use crate::error::{DataReadError, DataWriteError}; pub trait RWData<DataType> { /// Implement read logic /// Given a path, return the specific data - fn read(path: &PathBuf) -> impl Future<Output = Result<DataType, DataReadError>> + Send + Sync; + fn read(path: &Path) -> impl Future<Output = Result<DataType, DataReadError>> + Send + Sync; /// Implement write logic /// Given data and a path, write to the filesystem fn write( data: DataType, - path: &PathBuf, + path: &Path, ) -> impl Future<Output = Result<(), DataWriteError>> + Send + Sync; /// Provide test data @@ -42,10 +42,10 @@ pub struct FooData { } impl RWData<FooData> for FooData { - async fn read(path: &PathBuf) -> Result<FooData, DataReadError> { + async fn read(path: &Path) -> Result<FooData, DataReadError> { let content = tokio::fs::read_to_string(path) .await - .map_err(|e| DataReadError::IoError(e))?; + .map_err(DataReadError::IoError)?; let parts: Vec<&str> = content.split('=').collect(); if parts.len() != 2 { return Err(DataReadError::ParseError("Invalid format".to_string())); @@ -57,11 +57,11 @@ impl RWData<FooData> for FooData { Ok(FooData { age, name }) } - async fn write(data: FooData, path: &PathBuf) -> Result<(), DataWriteError> { + async fn write(data: FooData, path: &Path) -> Result<(), DataWriteError> { let content = format!("{}={}", data.name, data.age); tokio::fs::write(path, content) .await - .map_err(|e| DataWriteError::IoError(e))?; + .map_err(DataWriteError::IoError)?; Ok(()) } @@ -75,6 +75,6 @@ impl RWData<FooData> for FooData { fn verify_data(data_a: FooData, data_b: FooData) -> bool { crate::ensure_eq!(data_a.age, data_b.age); crate::ensure_eq!(data_a.name, data_b.name); - return true; + true } } diff --git a/systems/_asset/test/src/lib.rs b/systems/_asset/test/src/lib.rs index 4b62028..d7bf653 100644 --- a/systems/_asset/test/src/lib.rs +++ b/systems/_asset/test/src/lib.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::Path; use asset_system::{ RWDataTest, ensure_eq, @@ -13,10 +13,10 @@ pub struct FooData { } impl RWData<FooData> for FooData { - async fn read(path: &PathBuf) -> Result<FooData, DataReadError> { + async fn read(path: &Path) -> Result<FooData, DataReadError> { let content = tokio::fs::read_to_string(path) .await - .map_err(|e| DataReadError::IoError(e))?; + .map_err(DataReadError::IoError)?; let parts: Vec<&str> = content.split('=').collect(); if parts.len() != 2 { return Err(DataReadError::ParseError("Invalid format".to_string())); @@ -28,11 +28,11 @@ impl RWData<FooData> for FooData { Ok(FooData { age, name }) } - async fn write(data: FooData, path: &PathBuf) -> Result<(), DataWriteError> { + async fn write(data: FooData, path: &Path) -> Result<(), DataWriteError> { let content = format!("{}={}", data.name, data.age); tokio::fs::write(path, content) .await - .map_err(|e| DataWriteError::IoError(e))?; + .map_err(DataWriteError::IoError)?; Ok(()) } @@ -46,6 +46,6 @@ impl RWData<FooData> for FooData { fn verify_data(data_a: FooData, data_b: FooData) -> bool { ensure_eq!(data_a.age, data_b.age); ensure_eq!(data_a.name, data_b.name); - return true; + true } } diff --git a/systems/_constants/macros/src/lib.rs b/systems/_constants/macros/src/lib.rs index 7384182..90419c1 100644 --- a/systems/_constants/macros/src/lib.rs +++ b/systems/_constants/macros/src/lib.rs @@ -28,7 +28,7 @@ pub fn constants(attr: TokenStream, item: TokenStream) -> TokenStream { { // Process constant and generate functions if let Some((rust_func, ffi_func)) = - process_constant(&prefix, const_name, const_value) + process_constant(&prefix, const_name, &const_value) { generated_functions.push(rust_func); generated_ffi_functions.push(ffi_func); @@ -51,12 +51,12 @@ pub fn constants(attr: TokenStream, item: TokenStream) -> TokenStream { } fn extract_const_name_and_value(assign: &syn::ExprAssign) -> Option<(Ident, Box<Expr>)> { - if let Expr::Path(path) = &*assign.left { - if let Some(ident) = path.path.get_ident() { - let const_name = ident.clone(); - let const_value = assign.right.clone(); - return Some((const_name, const_value)); - } + if let Expr::Path(path) = &*assign.left + && let Some(ident) = path.path.get_ident() + { + let const_name = ident.clone(); + let const_value = assign.right.clone(); + return Some((const_name, const_value)); } None } @@ -64,12 +64,12 @@ fn extract_const_name_and_value(assign: &syn::ExprAssign) -> Option<(Ident, Box< fn process_constant( prefix: &str, const_name: Ident, - const_value: Box<Expr>, + const_value: &Expr, ) -> Option<(proc_macro2::TokenStream, proc_macro2::TokenStream)> { if let Expr::Lit(ExprLit { lit: Lit::Str(lit_str), .. - }) = *const_value + }) = const_value { let value_str = lit_str.value(); let value_span = lit_str.span(); @@ -209,18 +209,16 @@ fn generate_functions_with_params( let ffi_func = quote! { #[unsafe(no_mangle)] #[allow(nonstandard_style)] - pub extern "C" fn #ffi_fn_ident(#(#ffi_param_decls),*) -> *mut libc::c_char { - unsafe { - #(#ffi_param_checks)* + pub unsafe extern "C" fn #ffi_fn_ident(#(#ffi_param_decls),*) -> *mut libc::c_char { + #(#ffi_param_checks)* - #(#ffi_param_conversions)* + #(#ffi_param_conversions)* - let result = format!(#format_str, #(#ffi_format_args),*); + let result = format!(#format_str, #(#ffi_format_args),*); - match std::ffi::CString::new(result) { - Ok(c) => c.into_raw(), - Err(_) => std::ptr::null_mut(), - } + match std::ffi::CString::new(result) { + Ok(c) => c.into_raw(), + Err(_) => std::ptr::null_mut(), } } }; diff --git a/systems/_framework/src/space.rs b/systems/_framework/src/space.rs index 315bf2b..166120f 100644 --- a/systems/_framework/src/space.rs +++ b/systems/_framework/src/space.rs @@ -52,7 +52,7 @@ impl<T: SpaceRoot> Space<T> { _ => path.to_path_buf(), }; - if !find_space_root_with(&path, &pattern).is_ok() { + if find_space_root_with(&path, pattern).is_err() { T::create_space(&path).await?; } Ok(()) @@ -98,10 +98,10 @@ impl<T: SpaceRoot> Space<T> { /// Otherwise, it is found using the pattern from `T::get_pattern()`. pub fn space_dir(&self, current_dir: impl Into<PathBuf>) -> Result<PathBuf, SpaceError> { // First try to read from cache - if let Ok(lock) = self.space_dir.read() { - if let Some(cached_dir) = lock.as_ref() { - return Ok(cached_dir.clone()); - } + if let Ok(lock) = self.space_dir.read() + && let Some(cached_dir) = lock.as_ref() + { + return Ok(cached_dir.clone()); } // Cache miss, find the space directory @@ -399,7 +399,7 @@ impl<T: SpaceRoot> AsRef<T> for Space<T> { impl<T: SpaceRoot> Deref for Space<T> { type Target = T; fn deref(&self) -> &Self::Target { - &self.as_ref() + self.as_ref() } } @@ -427,7 +427,7 @@ pub enum SpaceRootFindPattern { /// /// For the full implementation, see `find_space_root_with` pub fn find_space_root(pattern: &SpaceRootFindPattern) -> Result<PathBuf, SpaceError> { - find_space_root_with(¤t_dir()?, &pattern) + find_space_root_with(¤t_dir()?, pattern) } /// Find the space directory containing the specified directory, @@ -500,7 +500,7 @@ pub fn find_space_root_with( path.join(dir_name).is_dir() }), SpaceRootFindPattern::IncludeFile(file_name) => { - Box::new(move |path| path.join(&file_name).is_file()) + Box::new(move |path| path.join(file_name).is_file()) } // For absolute paths, return directly diff --git a/systems/sheet/macros/src/lib.rs b/systems/sheet/macros/src/lib.rs index 2990f7e..ea2b139 100644 --- a/systems/sheet/macros/src/lib.rs +++ b/systems/sheet/macros/src/lib.rs @@ -41,8 +41,8 @@ fn parse_id_version(input: &str) -> Result<(bool, u32, u16), String> { let trimmed = input.trim(); // Check if it starts with ~ for local - let (remote, id_part) = if trimmed.starts_with('~') { - (false, &trimmed[1..]) + let (remote, id_part) = if let Some(stripped) = trimmed.strip_prefix('~') { + (false, stripped) } else { (true, trimmed) }; diff --git a/systems/sheet/src/compare.rs b/systems/sheet/src/compare.rs index b5b44b4..95b1aa3 100644 --- a/systems/sheet/src/compare.rs +++ b/systems/sheet/src/compare.rs @@ -7,7 +7,7 @@ use std::cmp::Ordering; /// 4. All other Unicode characters (in their natural order) /// /// The comparison is lexicographic: the first differing element determines the order. -pub fn compare_vec_string(a: &Vec<String>, b: &Vec<String>) -> std::cmp::Ordering { +pub fn compare_vec_string(a: &[String], b: &[String]) -> std::cmp::Ordering { use std::cmp::Ordering; for (left, right) in a.iter().zip(b.iter()) { diff --git a/systems/sheet/src/index_source.rs b/systems/sheet/src/index_source.rs index 43508f2..b11a6b6 100644 --- a/systems/sheet/src/index_source.rs +++ b/systems/sheet/src/index_source.rs @@ -62,7 +62,7 @@ impl IndexSource { impl PartialEq for IndexSource { fn eq(&self, other: &Self) -> bool { - &self.remote == &other.remote && &self.id == &other.id && &self.ver == &other.ver + self.remote == other.remote && self.id == other.id && self.ver == other.ver } } @@ -158,12 +158,6 @@ impl IndexSource { impl std::fmt::Display for IndexSource { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let local_symbol = if self.remote { "" } else { "~" }; - write!( - f, - "{}{}/{}", - local_symbol, - self.id.to_string(), - self.ver.to_string() - ) + write!(f, "{}{}/{}", local_symbol, self.id, self.ver) } } diff --git a/systems/sheet/src/index_source/alias.rs b/systems/sheet/src/index_source/alias.rs index d50c183..8b2cd5b 100644 --- a/systems/sheet/src/index_source/alias.rs +++ b/systems/sheet/src/index_source/alias.rs @@ -139,31 +139,30 @@ async fn get_or_create_alias_file( .read(true) .write(true) .create(true) + .truncate(false) .open(&file_path) .await - .map_err(|e| IDAliasError::Io(e))?; + .map_err(IDAliasError::Io)?; - let metadata = file.metadata().await.map_err(|e| IDAliasError::Io(e))?; + let metadata = file.metadata().await.map_err(IDAliasError::Io)?; if metadata.len() != FILE_SIZE { drop(file); let file = OpenOptions::new() .write(true) .create(true) - .truncate(true) + .truncate(false) .open(&file_path) .await - .map_err(|e| IDAliasError::Io(e))?; + .map_err(IDAliasError::Io)?; - file.set_len(FILE_SIZE) - .await - .map_err(|e| IDAliasError::Io(e))?; + file.set_len(FILE_SIZE).await.map_err(IDAliasError::Io)?; let file = OpenOptions::new() .read(true) .write(true) .open(&file_path) .await - .map_err(|e| IDAliasError::Io(e))?; + .map_err(IDAliasError::Io)?; Ok(file) } else { diff --git a/systems/sheet/src/lazy.rs b/systems/sheet/src/lazy.rs index 2278704..c9ba9df 100644 --- a/systems/sheet/src/lazy.rs +++ b/systems/sheet/src/lazy.rs @@ -8,13 +8,13 @@ macro_rules! lazy_node { #[macro_export] macro_rules! lazy_idx { ($idx:expr, $ver:expr) => { - crate::index_source::IndexSource::new(false, $idx, $ver) + $crate::index_source::IndexSource::new(false, $idx, $ver) }; } #[macro_export] macro_rules! lazy_ridx { ($idx:expr, $ver:expr) => { - crate::index_source::IndexSource::new(true, $idx, $ver) + $crate::index_source::IndexSource::new(true, $idx, $ver) }; } diff --git a/systems/sheet/src/mapping.rs b/systems/sheet/src/mapping.rs index 2e6645e..c1bbafd 100644 --- a/systems/sheet/src/mapping.rs +++ b/systems/sheet/src/mapping.rs @@ -171,7 +171,7 @@ impl LocalMapping { /// Clone and generate a MappingBuf from LocalMapping pub fn to_mapping_buf_cloned(&self, sheet_name: impl Into<String>) -> MappingBuf { - MappingBuf::new(sheet_name.into(), self.val.clone(), self.source.clone()) + MappingBuf::new(sheet_name.into(), self.val.clone(), self.source) } /// Generate a MappingBuf from LocalMapping @@ -235,7 +235,7 @@ impl MappingBuf { /// /// Additionally, if the length of the given forward value exceeds `u8::MAX`, it will also return None pub fn to_local_mapping_cloned(&self, forward: &LocalMappingForward) -> Option<LocalMapping> { - LocalMapping::new(self.val.clone(), self.source.clone(), forward.clone()) + LocalMapping::new(self.val.clone(), self.source, forward.clone()) } /// Generate a LocalMapping from MappingBuf @@ -262,7 +262,7 @@ impl<'a> Mapping<'a> { /// Get the sheet name of Mapping pub fn sheet_name(&self) -> &str { - &self.sheet_name + self.sheet_name } /// Build a Vec of Mapping values from the stored address @@ -276,7 +276,7 @@ impl<'a> Mapping<'a> { /// Get the value str of Mapping pub fn value_str(&self) -> &str { - &self.val + self.val } /// Get the IndexSource of Mapping @@ -301,7 +301,6 @@ impl<'a> Mapping<'a> { fmt_path_str(self.val) .unwrap_or_default() .split('/') - .into_iter() .map(|s| s.to_string()) .collect(), self.source, @@ -320,7 +319,6 @@ impl<'a> Mapping<'a> { fmt_path_str(self.val) .unwrap_or_default() .split("/") - .into_iter() .map(|s| s.to_string()) .collect(), self.source, @@ -404,36 +402,26 @@ impl std::fmt::Display for LocalMapping { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match &self.forward { LocalMappingForward::Latest => { - write!( - f, - "\"{}\" => \"{}\"", - self.val.join("/"), - self.source.to_string() - ) + write!(f, "\"{}\" => \"{}\"", self.val.join("/"), self.source) } LocalMappingForward::Ref { sheet_name } => { write!( f, "\"{}\" => \"{}\" => \"{}\"", self.val.join("/"), - self.source.to_string(), + self.source, sheet_name ) } LocalMappingForward::Version { version } => { if &self.mapped_version() == version { - write!( - f, - "\"{}\" == \"{}\"", - self.val.join("/"), - self.source.to_string(), - ) + write!(f, "\"{}\" == \"{}\"", self.val.join("/"), self.source,) } else { write!( f, "\"{}\" => \"{}\" == \"{}\"", self.val.join("/"), - self.source.to_string(), + self.source, version ) } @@ -556,7 +544,7 @@ fn join_helper(nodes: String, mut mapping_buf_val: Vec<String>) -> Vec<String> { } } - return mapping_buf_val; + mapping_buf_val } // Implement mutual comparison for MappingBuf and Mapping @@ -637,7 +625,7 @@ impl std::borrow::Borrow<Vec<String>> for MappingBuf { /// ``` pub fn node(str: impl Into<String>) -> Vec<String> { let str = just_fmt::fmt_path::fmt_path_str(str).unwrap_or_default(); - str.split("/").into_iter().map(|f| f.to_string()).collect() + str.split("/").map(|f| f.to_string()).collect() } // Implement comparison for LocalMapping diff --git a/systems/sheet/src/mapping/parse.rs b/systems/sheet/src/mapping/parse.rs index e203c96..7460ffd 100644 --- a/systems/sheet/src/mapping/parse.rs +++ b/systems/sheet/src/mapping/parse.rs @@ -178,9 +178,7 @@ impl TryFrom<&str> for LocalMapping { Ok(LocalMapping { val, source, - forward: LocalMappingForward::Ref { - sheet_name: sheet_name, - }, + forward: LocalMappingForward::Ref { sheet_name }, }) } _ => Err(ParseMappingError::InvalidMapping), diff --git a/systems/sheet/src/sheet.rs b/systems/sheet/src/sheet.rs index fdcdd67..96fca9a 100644 --- a/systems/sheet/src/sheet.rs +++ b/systems/sheet/src/sheet.rs @@ -1,7 +1,6 @@ use std::{ collections::HashSet, fs::File, - mem::replace, path::{Path, PathBuf}, }; @@ -139,14 +138,14 @@ impl std::fmt::Display for SheetEditItem { write!(f, "erase \"{}\"", display_node_helper(node),) } SheetEditItem::InsertMapping { mapping } => { - write!(f, "Insert {}", mapping.to_string()) + write!(f, "Insert {}", mapping) } SheetEditItem::ReplaceSource { node, source } => { write!( f, "Replace \"{}\" => \"{}\"", display_node_helper(node), - source.to_string() + source ) } SheetEditItem::UpdateForward { node, forward } => match forward { @@ -177,7 +176,7 @@ impl std::fmt::Display for SheetEditItem { } #[inline(always)] -fn display_node_helper(n: &Vec<String>) -> String { +fn display_node_helper(n: &[String]) -> String { n.join("/") } @@ -201,7 +200,7 @@ impl SheetData { } /// Load MMAP from a Sheet file - pub fn mmap<'a>(sheet_file: impl AsRef<Path>) -> std::io::Result<SheetDataMmap> { + pub fn mmap(sheet_file: impl AsRef<Path>) -> std::io::Result<SheetDataMmap> { let file = File::open(sheet_file.as_ref())?; // SAFETY: The file has been successfully opened and is managed by the SheetDataMmap wrapper @@ -244,7 +243,7 @@ impl SheetDataMmap { } /// Load mapping information from Sheet file at high speed and copy into LocalMapping - pub fn mp_c<'a>(&self, node: &[&str]) -> Result<Option<LocalMapping>, ReadSheetDataError> { + pub fn mp_c(&self, node: &[&str]) -> Result<Option<LocalMapping>, ReadSheetDataError> { match self.mp(node)? { Some((mapping, forward)) => { // Note: @@ -291,10 +290,8 @@ impl Sheet { /// Read from Sheet data and clone into MappingBuf pub fn read_mapping_buf(&self, value: &Vec<String>) -> Option<MappingBuf> { - match self.read_local_mapping(value) { - Some(v) => Some(v.to_mapping_buf_cloned(&self.name)), - None => None, - } + self.read_local_mapping(value) + .map(|v| v.to_mapping_buf_cloned(&self.name)) } /// Insert mapping move @@ -410,7 +407,7 @@ impl Sheet { /// Apply changes pub fn apply(&mut self) -> Result<(), SheetApplyError> { - let items = replace(&mut self.edit.list, Vec::new()); + let items = std::mem::take(&mut self.edit.list); for item in items { match item { SheetEditItem::DoNothing => continue, @@ -516,9 +513,9 @@ impl TryFrom<&str> for SheetData { continue; } let mapping = LocalMapping::try_from(line)?; - let _ = sheet.insert_mapping(mapping)?; + sheet.insert_mapping(mapping)?; } - let _ = sheet.apply()?; + sheet.apply()?; Ok(sheet.unpack()) } } @@ -552,7 +549,7 @@ impl TryFrom<&[u8]> for SheetData { } impl RWData<SheetData> for SheetData { - async fn read(path: &PathBuf) -> Result<SheetData, asset_system::error::DataReadError> { + async fn read(path: &Path) -> Result<SheetData, asset_system::error::DataReadError> { let mut data = SheetData::empty(); data.full_read(path).await.map_err(|e| match e { ReadSheetDataError::IOErr(error) => DataReadError::IoError(error), @@ -562,11 +559,11 @@ impl RWData<SheetData> for SheetData { async fn write( data: SheetData, - path: &PathBuf, + path: &Path, ) -> Result<(), asset_system::error::DataWriteError> { tokio::fs::write(path, data.as_bytes()) .await - .map_err(|e| asset_system::error::DataWriteError::IoError(e.into())) + .map_err(asset_system::error::DataWriteError::IoError) } fn test_data() -> SheetData { diff --git a/systems/sheet/src/sheet/v1/constants.rs b/systems/sheet/src/sheet/v1/constants.rs index 7073278..eec7b5c 100644 --- a/systems/sheet/src/sheet/v1/constants.rs +++ b/systems/sheet/src/sheet/v1/constants.rs @@ -7,8 +7,7 @@ // [OFFSET_INDEX_TABLE: u32] pub const CURRENT_SHEET_VERSION: u8 = 1; -pub const HEADER_SIZE: usize = 0 - + 1 // SHEET_VERSION +pub const HEADER_SIZE: usize = 1 // SHEET_VERSION + 2 // MAPPING_BUCKET_COUNT + 4 // INDEX_COUNT + 4 // OFFSET_MAPPING_DIR @@ -21,8 +20,7 @@ pub const HEADER_SIZE: usize = 0 // [BUCKET_OFFSET: u32] // [BUCKET_LENGTH: u32] -pub const MAPPING_DIR_ENTRY_SIZE: usize = 0 - + 4 // BUCKET_HASH_PREFIX +pub const MAPPING_DIR_ENTRY_SIZE: usize = 4 // BUCKET_HASH_PREFIX + 4 // BUCKET_OFFSET + 4 // BUCKET_LENGTH ; @@ -36,8 +34,7 @@ pub const MAPPING_DIR_ENTRY_SIZE: usize = 0 // [FORWARD_INFO_BYTES: ?] // [INDEX_OFFSET: u32] -pub const MAPPING_BUCKET_MIN_SIZE: usize = 0 - + 1 // KEY_LEN +pub const MAPPING_BUCKET_MIN_SIZE: usize = 1 // KEY_LEN + 1 // FORWARD_TYPE + 1 // FORWARD_INFO_LEN + 2 // KEY_BYTES (MIN:1) + FORWARD_INFO_BYTES (MIN:1) @@ -51,8 +48,7 @@ pub const MAPPING_BUCKET_MIN_SIZE: usize = 0 // [REMOTE_FLAG: u8] // [RESERVED: u8; 3] -pub const INDEX_ENTRY_SIZE: usize = 0 - + 4 // INDEX_ID +pub const INDEX_ENTRY_SIZE: usize = 4 // INDEX_ID + 2 // INDEX_VERSION + 1 // REMOTE_FLAG + 3 // RESERVED diff --git a/systems/sheet/src/sheet/v1/writer.rs b/systems/sheet/src/sheet/v1/writer.rs index 4c580b2..fdc4caa 100644 --- a/systems/sheet/src/sheet/v1/writer.rs +++ b/systems/sheet/src/sheet/v1/writer.rs @@ -18,9 +18,9 @@ pub fn convert_sheet_data_to_bytes(sheet_data: SheetData) -> Vec<u8> { for mapping in &mappings { let source = mapping.index_source(); let key = (source.is_remote(), source.id(), source.version()); - if !source_to_offset.contains_key(&key) { + if let std::collections::hash_map::Entry::Vacant(e) = source_to_offset.entry(key) { let offset = index_sources.len() as u32; - source_to_offset.insert(key, offset); + e.insert(offset); index_sources.push(IndexSource::new( source.is_remote(), source.id(), @@ -36,10 +36,7 @@ pub fn convert_sheet_data_to_bytes(sheet_data: SheetData) -> Vec<u8> { for mapping in mappings { let hash = calculate_path_hash(mapping.value()); let bucket_key = hash >> 16; // Take high 16 bits as bucket key - buckets - .entry(bucket_key) - .or_insert_with(Vec::new) - .push(mapping); + buckets.entry(bucket_key).or_default().push(mapping); } let bucket_count = buckets.len() as u16; diff --git a/systems/vault/src/vault/config.rs b/systems/vault/src/vault/config.rs index 329f78e..c552e15 100644 --- a/systems/vault/src/vault/config.rs +++ b/systems/vault/src/vault/config.rs @@ -1,3 +1,5 @@ +use std::path::Path; + use asset_system::{RWDataTest, rw::RWData}; use config_system::rw::{read_config, write_config}; use serde::{Deserialize, Serialize}; @@ -6,30 +8,26 @@ use serde::{Deserialize, Serialize}; pub struct VaultConfig {} impl RWData<VaultConfig> for VaultConfig { - async fn read( - path: &std::path::PathBuf, - ) -> Result<VaultConfig, asset_system::error::DataReadError> { + async fn read(path: &Path) -> Result<VaultConfig, asset_system::error::DataReadError> { let read_config = read_config(path).await; match read_config { Ok(config) => Ok(config), Err(e) => Err(asset_system::error::DataReadError::IoError( - std::io::Error::new(std::io::ErrorKind::Other, e), + std::io::Error::other(e), )), } } async fn write( data: VaultConfig, - path: &std::path::PathBuf, + path: &Path, ) -> Result<(), asset_system::error::DataWriteError> { let write_config = write_config(path, &data).await; match write_config { Ok(_) => Ok(()), - Err(e) => { - return Err(asset_system::error::DataWriteError::IoError( - std::io::Error::new(std::io::ErrorKind::Other, e), - )); - } + Err(e) => Err(asset_system::error::DataWriteError::IoError( + std::io::Error::other(e), + )), } } @@ -38,6 +36,6 @@ impl RWData<VaultConfig> for VaultConfig { } fn verify_data(data_a: VaultConfig, data_b: VaultConfig) -> bool { - &data_a == &data_b + data_a == data_b } } diff --git a/systems/vault/src/vault/manager.rs b/systems/vault/src/vault/manager.rs index bae26d4..249d020 100644 --- a/systems/vault/src/vault/manager.rs +++ b/systems/vault/src/vault/manager.rs @@ -8,6 +8,12 @@ pub struct VaultManager { space: Space<Vault>, } +impl Default for VaultManager { + fn default() -> Self { + Self::new() + } +} + impl VaultManager { pub fn new() -> Self { VaultManager { diff --git a/systems/workspace/src/workspace/config.rs b/systems/workspace/src/workspace/config.rs index f43dc0e..a494db3 100644 --- a/systems/workspace/src/workspace/config.rs +++ b/systems/workspace/src/workspace/config.rs @@ -1,4 +1,4 @@ -use std::{io::Error, path::PathBuf}; +use std::{io::Error, path::Path}; use asset_system::{ RWDataTest, @@ -85,27 +85,19 @@ impl WorkspaceConfig { } impl RWData<WorkspaceConfig> for WorkspaceConfig { - async fn read(path: &PathBuf) -> Result<WorkspaceConfig, DataReadError> { + async fn read(path: &Path) -> Result<WorkspaceConfig, DataReadError> { let read_config = read_config(path).await; match read_config { Ok(config) => Ok(config), - Err(e) => Err(DataReadError::IoError(Error::new( - std::io::ErrorKind::Other, - e, - ))), + Err(e) => Err(DataReadError::IoError(Error::other(e))), } } - async fn write(data: WorkspaceConfig, path: &PathBuf) -> Result<(), DataWriteError> { + async fn write(data: WorkspaceConfig, path: &Path) -> Result<(), DataWriteError> { let write_config = write_config(path, &data).await; match write_config { Ok(_) => Ok(()), - Err(e) => { - return Err(DataWriteError::IoError(Error::new( - std::io::ErrorKind::Other, - e, - ))); - } + Err(e) => Err(DataWriteError::IoError(Error::other(e))), } } @@ -114,6 +106,6 @@ impl RWData<WorkspaceConfig> for WorkspaceConfig { } fn verify_data(data_a: WorkspaceConfig, data_b: WorkspaceConfig) -> bool { - &data_a == &data_b + data_a == data_b } } diff --git a/systems/workspace/src/workspace/manager.rs b/systems/workspace/src/workspace/manager.rs index fef36ab..7e8fc47 100644 --- a/systems/workspace/src/workspace/manager.rs +++ b/systems/workspace/src/workspace/manager.rs @@ -10,6 +10,12 @@ pub struct WorkspaceManager { pub(crate) space: Space<Workspace>, } +impl Default for WorkspaceManager { + fn default() -> Self { + Self::new() + } +} + impl WorkspaceManager { pub fn new() -> Self { WorkspaceManager { diff --git a/systems/workspace/src/workspace/manager/id_aliases.rs b/systems/workspace/src/workspace/manager/id_aliases.rs index a5a509c..4ce659d 100644 --- a/systems/workspace/src/workspace/manager/id_aliases.rs +++ b/systems/workspace/src/workspace/manager/id_aliases.rs @@ -51,7 +51,7 @@ impl WorkspaceManager { let aliases_dir = self.get_space().local_path(workspace_dir_id_mapping())?; IndexSourceAliasesManager::write_alias(aliases_dir, local_id, remote_id) .await - .map_err(|e| WorkspaceOperationError::IDAliasError(e)) + .map_err(WorkspaceOperationError::IDAliasError) } /// Delete a alias between local and remote IDs @@ -59,7 +59,7 @@ impl WorkspaceManager { let aliases_dir = self.get_space().local_path(workspace_dir_id_mapping())?; IndexSourceAliasesManager::delete_alias(aliases_dir, local_id) .await - .map_err(|e| WorkspaceOperationError::IDAliasError(e)) + .map_err(WorkspaceOperationError::IDAliasError) } /// Check if a alias exists between local and remote IDs @@ -67,6 +67,6 @@ impl WorkspaceManager { let aliases_dir = self.get_space().local_path(workspace_dir_id_mapping())?; IndexSourceAliasesManager::alias_exists(aliases_dir, local_id) .await - .map_err(|e| WorkspaceOperationError::IDAliasError(e)) + .map_err(WorkspaceOperationError::IDAliasError) } } diff --git a/systems/workspace/src/workspace/manager/sheet_state.rs b/systems/workspace/src/workspace/manager/sheet_state.rs index b7cd4fd..eddfa84 100644 --- a/systems/workspace/src/workspace/manager/sheet_state.rs +++ b/systems/workspace/src/workspace/manager/sheet_state.rs @@ -47,7 +47,7 @@ impl WorkspaceManager { if sheet_path.exists() { // If reading fails, treat it as if the sheet does not exist and return `None` sheet_data.full_read(sheet_path).await.ok()?; - return Some(sheet_data.pack(sheet_name)); + Some(sheet_data.pack(sheet_name)) } else { None } @@ -72,7 +72,7 @@ impl WorkspaceManager { pub fn get_sheet_path(&self, sheet_name: impl AsRef<str>) -> PathBuf { let sheet_name = sheet_name.as_ref(); self.space - .local_path(workspace_file_sheet(&sheet_name)) + .local_path(workspace_file_sheet(sheet_name)) // The `local_path` only produces path formatting errors. // If the path cannot be guaranteed to be correct, // execution should not continue, so we unwrap() @@ -85,12 +85,11 @@ impl WorkspaceManager { if let Ok(mut read_dir) = self.space.read_dir(workspace_dir_local_sheets()).await { while let Some(entry) = read_dir.next_entry().await.ok().flatten() { let path = entry.path(); - if path.is_file() { - if let Some(file_name) = path.file_stem() { - if let Some(name_str) = file_name.to_str() { - sheet_names.push(name_str.to_string()); - } - } + if path.is_file() + && let Some(file_name) = path.file_stem() + && let Some(name_str) = file_name.to_str() + { + sheet_names.push(name_str.to_string()); } } } |
