summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/utils/tcp_connection/src/target.rs2
-rw-r--r--crates/utils/tcp_connection/tcp_connection_test/src/test_tcp_target_build.rs3
-rw-r--r--crates/vcs/src/workspace/local.rs8
-rw-r--r--crates/vcs/src/workspace/vault.rs8
-rw-r--r--crates/vcs/src/workspace/vault/virtual_file.rs11
5 files changed, 13 insertions, 19 deletions
diff --git a/crates/utils/tcp_connection/src/target.rs b/crates/utils/tcp_connection/src/target.rs
index a8cb594..88b931a 100644
--- a/crates/utils/tcp_connection/src/target.rs
+++ b/crates/utils/tcp_connection/src/target.rs
@@ -104,7 +104,7 @@ where
}
/// Try to create target by string
- pub fn from_str<'a>(addr_str: impl Into<&'a str>) -> Result<Self, AddrParseError> {
+ pub fn from_address_str<'a>(addr_str: impl Into<&'a str>) -> Result<Self, AddrParseError> {
let socket_addr = SocketAddr::from_str(addr_str.into());
match socket_addr {
Ok(socket_addr) => Ok(Self::from_addr(socket_addr.ip(), socket_addr.port())),
diff --git a/crates/utils/tcp_connection/tcp_connection_test/src/test_tcp_target_build.rs b/crates/utils/tcp_connection/tcp_connection_test/src/test_tcp_target_build.rs
index 0e1ed67..bcaada3 100644
--- a/crates/utils/tcp_connection/tcp_connection_test/src/test_tcp_target_build.rs
+++ b/crates/utils/tcp_connection/tcp_connection_test/src/test_tcp_target_build.rs
@@ -7,7 +7,8 @@ fn test_tcp_test_target_build() {
let host = "127.0.0.1:8080";
// Test build target by string
- let Ok(target) = TcpServerTarget::<ExampleClientHandle, ExampleServerHandle>::from_str(host)
+ let Ok(target) =
+ TcpServerTarget::<ExampleClientHandle, ExampleServerHandle>::from_address_str(host)
else {
panic!("Test target built failed from a target addr `{}`", host);
};
diff --git a/crates/vcs/src/workspace/local.rs b/crates/vcs/src/workspace/local.rs
index 6beb842..8399b6d 100644
--- a/crates/vcs/src/workspace/local.rs
+++ b/crates/vcs/src/workspace/local.rs
@@ -24,17 +24,13 @@ impl LocalWorkspace {
/// Initialize local workspace.
pub fn init(config: LocalConfig, local_path: impl Into<PathBuf>) -> Option<Self> {
- let Some(local_path) = find_local_path(local_path) else {
- return None;
- };
+ let local_path = find_local_path(local_path)?;
Some(Self { config, local_path })
}
/// Initialize local workspace in the current directory.
pub fn init_current_dir(config: LocalConfig) -> Option<Self> {
- let Some(local_path) = current_local_path() else {
- return None;
- };
+ let local_path = current_local_path()?;
Some(Self { config, local_path })
}
diff --git a/crates/vcs/src/workspace/vault.rs b/crates/vcs/src/workspace/vault.rs
index 912c6e2..7f52c9c 100644
--- a/crates/vcs/src/workspace/vault.rs
+++ b/crates/vcs/src/workspace/vault.rs
@@ -34,17 +34,13 @@ impl Vault {
/// Initialize vault
pub fn init(config: VaultConfig, vault_path: impl Into<PathBuf>) -> Option<Self> {
- let Some(vault_path) = find_vault_path(vault_path) else {
- return None;
- };
+ let vault_path = find_vault_path(vault_path)?;
Some(Self { config, vault_path })
}
/// Initialize vault
pub fn init_current_dir(config: VaultConfig) -> Option<Self> {
- let Some(vault_path) = current_vault_path() else {
- return None;
- };
+ let vault_path = current_vault_path()?;
Some(Self { config, vault_path })
}
diff --git a/crates/vcs/src/workspace/vault/virtual_file.rs b/crates/vcs/src/workspace/vault/virtual_file.rs
index 95f3d8c..c83f700 100644
--- a/crates/vcs/src/workspace/vault/virtual_file.rs
+++ b/crates/vcs/src/workspace/vault/virtual_file.rs
@@ -95,8 +95,8 @@ impl Vault {
// Generate index path of virtual file
fn vf_index(id: &VirtualFileId) -> Result<String, std::io::Error> {
// Remove VF_PREFIX if present
- let id_str = if id.starts_with(VF_PREFIX) {
- &id[VF_PREFIX.len()..]
+ let id_str = if let Some(stripped) = id.strip_prefix(VF_PREFIX) {
+ stripped
} else {
id
};
@@ -237,9 +237,10 @@ impl Vault {
// Move temp file to virtual file directory
if let Some(parent) = move_path.parent()
- && !parent.exists() {
- fs::create_dir_all(parent).await?;
- }
+ && !parent.exists()
+ {
+ fs::create_dir_all(parent).await?;
+ }
fs::rename(receive_path, move_path).await?;
Ok(new_id)