Skip to content

Commit c0b12cd

Browse files
committed
fix: enhance FastStr conversion from u64
1 parent c7832e1 commit c0b12cd

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ redis-unsafe = ["redis"]
3535
rkyv = ["rkyv/alloc"]
3636
sqlx-mysql = ["std", "dep:sqlx", "dep:sqlx-mysql"]
3737
sqlx-mysql-unsafe = ["sqlx-mysql"]
38-
sea-orm = ["std", "dep:sea-orm"]
39-
38+
sea-orm = ["std", "dep:sea-orm", "itoa"]
4039

4140
[dev-dependencies]
4241
static_assertions = { version = "1" }

src/sea_orm.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl std::convert::From<FastStr> for sea_orm::Value {
1010

1111
impl sea_orm::TryFromU64 for FastStr {
1212
fn try_from_u64(value: u64) -> Result<Self, sea_orm::DbErr> {
13-
Ok(FastStr::from_string(value.to_string()))
13+
Ok(FastStr::new(itoa::Buffer::new().format(value)))
1414
}
1515
}
1616

@@ -56,6 +56,7 @@ mod tests {
5656
use super::*;
5757
use sea_orm::{
5858
entity::prelude::*, ActiveValue::Set, DerivePrimaryKey, MockDatabase, QueryTrait,
59+
TryFromU64 as _,
5960
};
6061

6162
mod test_book {
@@ -188,4 +189,12 @@ mod tests {
188189
.unwrap();
189190
assert_eq!(result, Some(test_book::Model { id: test_str }));
190191
}
192+
193+
#[tokio::test]
194+
async fn test_try_from_u64() {
195+
assert_eq!(
196+
FastStr::try_from_u64(1234567890),
197+
Ok(FastStr::from_static_str("1234567890"))
198+
);
199+
}
191200
}

0 commit comments

Comments
 (0)