Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e528e01

Browse files
authored
Merge pull request sfackler#1118 from laxjesse/split_once_in_lsn_from_str
use `split_once` instead of `split` to parse lsn strings
2 parents 270a29b + 9743630 commit e528e01

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

postgres-types/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
### Changed
6+
7+
* `FromStr` implementation for `PgLsn` no longer allocates a `Vec` when splitting an lsn string on it's `/`.
8+
39
## v0.2.6 - 2023-08-19
410

511
### Fixed

postgres-types/src/pg_lsn.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@ impl FromStr for PgLsn {
3333
type Err = ParseLsnError;
3434

3535
fn from_str(lsn_str: &str) -> Result<Self, Self::Err> {
36-
let split: Vec<&str> = lsn_str.split('/').collect();
37-
if split.len() == 2 {
38-
let (hi, lo) = (
39-
u64::from_str_radix(split[0], 16).map_err(|_| ParseLsnError(()))?,
40-
u64::from_str_radix(split[1], 16).map_err(|_| ParseLsnError(()))?,
41-
);
42-
Ok(PgLsn((hi << 32) | lo))
43-
} else {
44-
Err(ParseLsnError(()))
45-
}
36+
let Some((split_hi, split_lo)) = lsn_str.split_once('/') else {
37+
return Err(ParseLsnError(()));
38+
};
39+
let (hi, lo) = (
40+
u64::from_str_radix(split_hi, 16).map_err(|_| ParseLsnError(()))?,
41+
u64::from_str_radix(split_lo, 16).map_err(|_| ParseLsnError(()))?,
42+
);
43+
Ok(PgLsn((hi << 32) | lo))
4644
}
4745
}
4846

0 commit comments

Comments
 (0)