Skip to content

Commit

Permalink
Some small optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Jul 21, 2022
1 parent a7df1a1 commit 48890c7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tardis"
version = "0.1.0-alpha16"
version = "0.1.0-alpha17"
authors = ["gudaoxuri <i@sunisle.org>"]
description = "Elegant, clean Rust development framework"
keywords = ["http", "database", "web", "redis", "mq"]
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Do NOT use in production environment!**
* Containerized unit testing of mainstream middleware
* Multi-environment configuration
* Multi-application aggregation
* Configure encryption support
* Internationalization and localization support
* Commonly used operations (E.g. uniform error handling, encryption and decryption, regular checksums)

## ⚙️Feature description
Expand Down Expand Up @@ -102,7 +104,7 @@ async fn main() -> TardisResult<()> {
|-- webscoket WebSocket Usage Example
|-- cache Cache Usage Example
|-- mq Message Queue Usage Example
|-- todo A complete project usage example
|-- todos A complete project usage example
|-- multi-apps Multi-application aggregation example
|-- perf-test Performance test case
```
Expand All @@ -112,10 +114,12 @@ async fn main() -> TardisResult<()> {
* An `` failed to run custom build command for openssl-sys`` error occurs when running under Windows.The solution is as follows( @see https://github.com/sfackler/rust-openssl/issues/1062 ):
```shell
git clone https://github.com/Microsoft/vcpkg --depth=1
vcpkg/bootstrap-vcpkg.bat
vcpkg/vcpkg.exe integrate install
vcpkg/vcpkg.exe install openssl:x64-windows-static
cd vcpkg
bootstrap-vcpkg.bat
vcpkg.exe integrate install
vcpkg.exe install openssl:x64-windows-static
set OPENSSL_NO_VENDOR=1
set OPENSSL_DIR=<Current Dir>\packages\openssl_x64-windows-static
```

----
Expand Down
8 changes: 4 additions & 4 deletions src/basic/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ impl TardisError {
if let Some((message, regex)) = conf.get(code) {
let mut localized_message = message.clone();
if let Some(regex) = regex {
if let Some(cap) = regex.captures(default_message) {
return if let Some(cap) = regex.captures(default_message) {
for (idx, cap) in cap.iter().enumerate() {
if let Some(cap) = cap {
localized_message = localized_message.replace(&format!("{{{}}}", idx), cap.as_str());
}
}
return Ok(localized_message);
Ok(localized_message)
} else {
// Regex not match, fallback to default message
return Ok(default_message.to_string());
}
Ok(default_message.to_string())
};
}
// No regex, return default message
return Ok(message.to_string());
Expand Down
28 changes: 15 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
//! * Containerized unit testing of mainstream middleware
//! * Multi-environment configuration
//! * Multi-application aggregation
//! * Configure encryption support
//! * Internationalization and localization support
//! * Commonly used operations (E.g. uniform error handling, encryption and decryption, regular checksums)
//!
//! ## ⚙️Feature description
Expand Down Expand Up @@ -97,7 +99,7 @@
//!> |-- webscoket WebSocket Usage Example
//!> |-- cache Cache Usage Example
//!> |-- mq Message Queue Usage Example
//!> |-- todo A complete project usage example
//!> |-- todos A complete project usage example
//!> |-- multi-apps Multi-application aggregation example
//!> |-- perf-test Performance test case
Expand Down Expand Up @@ -451,7 +453,7 @@ impl TardisFuns {
};
}
}
TardisResult::Ok(())
Ok(())
}

pub fn inst<'a>(code: String, lang: Option<String>) -> TardisFunsInst<'a> {
Expand Down Expand Up @@ -571,17 +573,17 @@ impl TardisFuns {
/// ```
#[allow(non_upper_case_globals)]
#[cfg(feature = "crypto")]
pub const crypto: crate::basic::crypto::TardisCrypto = crate::basic::crypto::TardisCrypto {
key: crate::basic::crypto::TardisCryptoKey {},
hex: crate::basic::crypto::TardisCryptoHex {},
base64: crate::basic::crypto::TardisCryptoBase64 {},
aes: crate::basic::crypto::TardisCryptoAes {},
rsa: crate::basic::crypto::TardisCryptoRsa {},
pub const crypto: basic::crypto::TardisCrypto = basic::crypto::TardisCrypto {
key: basic::crypto::TardisCryptoKey {},
hex: basic::crypto::TardisCryptoHex {},
base64: basic::crypto::TardisCryptoBase64 {},
aes: basic::crypto::TardisCryptoAes {},
rsa: basic::crypto::TardisCryptoRsa {},
#[cfg(feature = "crypto_with_sm")]
sm4: crate::basic::crypto::TardisCryptoSm4 {},
sm4: basic::crypto::TardisCryptoSm4 {},
#[cfg(feature = "crypto_with_sm")]
sm2: crate::basic::crypto::TardisCryptoSm2 {},
digest: crate::basic::crypto::TardisCryptoDigest {},
sm2: basic::crypto::TardisCryptoSm2 {},
digest: basic::crypto::TardisCryptoDigest {},
};

/// Use the relational database feature / 使用关系型数据库功能
Expand Down Expand Up @@ -966,7 +968,7 @@ pub struct TardisFunsInst<'a> {
module_code: String,
err: TardisErrorWithExt,
#[cfg(feature = "reldb")]
db: Option<crate::db::reldb_client::TardisRelDBlConnection<'a>>,
db: Option<db::reldb_client::TardisRelDBlConnection<'a>>,
// Solve the 'a not used issue when the reldb feature is not enabled
#[cfg(not(feature = "reldb"))]
_t: Option<&'a str>,
Expand Down Expand Up @@ -1018,7 +1020,7 @@ impl<'a> TardisFunsInst<'a> {
}

#[cfg(feature = "reldb")]
pub fn db(&self) -> &crate::db::reldb_client::TardisRelDBlConnection<'a> {
pub fn db(&self) -> &db::reldb_client::TardisRelDBlConnection<'a> {
self.db.as_ref().expect("db is not initialized")
}

Expand Down

0 comments on commit 48890c7

Please sign in to comment.