Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit544abaa

Browse files
committed
fixup
1 parent2762312 commit544abaa

File tree

1 file changed

+39
-30
lines changed

1 file changed

+39
-30
lines changed

‎postgres-protocol/src/types/numeric.rs‎

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,33 @@ impl Numeric {
7676
pubfnsign(&self) ->NumericSign{
7777
self.sign
7878
}
79+
80+
fnnan() ->Self{
81+
Self{
82+
sign:NumericSign::NaN,
83+
scale:0,
84+
weight:0,
85+
digits:vec![],
86+
}
87+
}
88+
89+
fninfinity() ->Self{
90+
Self{
91+
sign:NumericSign::PositiveInfinity,
92+
scale:0,
93+
weight:0,
94+
digits:vec![],
95+
}
96+
}
97+
98+
fnnegative_infinity() ->Self{
99+
Self{
100+
sign:NumericSign::NegativeInfinity,
101+
scale:0,
102+
weight:0,
103+
digits:vec![],
104+
}
105+
}
79106
}
80107

81108
impl std::fmt::DisplayforNumeric{
@@ -161,33 +188,15 @@ impl FromStr for Numeric {
161188
letmut scale =0;
162189
letmut sign =NumericSign::Positive;
163190

164-
match value{
165-
"NaN" |"nan" =>{
166-
returnOk(Numeric{
167-
sign:NumericSign::NaN,
168-
scale:0,
169-
weight:0,
170-
digits:vec![],
171-
})
172-
}
173-
"Infinity" |"infinity" |"inf" =>{
174-
returnOk(Numeric{
175-
sign:NumericSign::PositiveInfinity,
176-
scale:0,
177-
weight:0,
178-
digits:vec![],
179-
})
180-
}
181-
"-Infinity" |"-infinity" |"-inf" =>{
182-
returnOk(Numeric{
183-
sign:NumericSign::NegativeInfinity,
184-
scale:0,
185-
weight:0,
186-
digits:vec![],
187-
})
188-
}
189-
_ =>{}
190-
};
191+
if value.eq_ignore_ascii_case("NaN"){
192+
returnOk(Numeric::nan());
193+
}
194+
if value.eq_ignore_ascii_case("Infinity") || value.eq_ignore_ascii_case("Inf"){
195+
returnOk(Numeric::infinity());
196+
}
197+
if value.eq_ignore_ascii_case("-Infinity") || value.eq_ignore_ascii_case("-Inf"){
198+
returnOk(Numeric::negative_infinity());
199+
}
191200

192201
letmut s = value.as_bytes();
193202
ifletSome(&b'-') = s.first(){
@@ -206,7 +215,7 @@ impl FromStr for Numeric {
206215

207216
ifletSome(mut e) = e{
208217
if e.is_empty(){
209-
returnErr("emptysientific notation string".into());
218+
returnErr("emptyscientific notation string".into());
210219
}
211220

212221
letmut positive =true;
@@ -221,7 +230,7 @@ impl FromStr for Numeric {
221230

222231
for&bin e{
223232
if !b.is_ascii_digit(){
224-
returnErr("sientific notation string contain non-digit character".into());
233+
returnErr("scientific notation string contain non-digit character".into());
225234
}
226235
exp = exp*10 +(b -b'0')asu16;
227236
}
@@ -591,7 +600,7 @@ mod test {
591600
}
592601

593602
#[test]
594-
fntest_from_sientific_notation(){
603+
fntest_from_scientific_notation(){
595604
let cases =&[
596605
(
597606
"2e4",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp