Closed Bug 1483288 Opened 6 years ago Closed 6 years ago

Provide more number conversions for mozprofile::preferences::Pref

Categories

(Testing :: Mozbase Rust, enhancement)

enhancement
Not set
normal

Tracking

(firefox63 fixed)

RESOLVED FIXED
mozilla63
Tracking Status
firefox63 --- fixed

People

(Reporter: ato, Assigned: ato)

Details

Attachments

(2 files)

geckodriver currently coerces the port number (u16) into u64 before
mozprofile::preferences converts it into PrefValue::U64.  We should
provide more implicit conversions in mozprofile so that the explicit
conversion in geckodriver is unnecessary.
Assignee: nobody → ato
Status: NEW → ASSIGNED
Allow i8, u8, i16, u64, i32, and u32 to be implicitly converted into
PrefValue::Int.  u64 is not supported because it would overflow,
so this still needs to be handled manually.

geckodriver stores the port number as u8 and this will allow it to
implicitly convert it to PrefValue::Int without using the unsafe
"as i64" coercion.
Attachment #9000000 - Flags: review?(hskupin)
Attachment #9000001 - Flags: review?(hskupin) → review+
Comment on attachment 9000000 [details] [diff] [review]
Provide more number conversions for mozprofile::preferences::PrefValue.

Review of attachment 9000000 [details] [diff] [review]:
-----------------------------------------------------------------

::: testing/mozbase/rust/mozprofile/src/preferences.rs
@@ +66,1 @@
>  impl From<i64> for PrefValue {

Please put a short note below here why u64 doesn't work.

@@ +120,5 @@
> +        assert_eq!(PrefValue::from(42u16), PrefValue::Int(42i64));
> +        assert_eq!(PrefValue::from(42i32), PrefValue::Int(42i64));
> +        assert_eq!(PrefValue::from(42u32), PrefValue::Int(42i64));
> +        assert_eq!(PrefValue::from(42i64), PrefValue::Int(42i64));
> +    }

Could we assert for an error in case of u64? Or will it refuse to compile? It might be the latter, right?
Attachment #9000000 - Flags: review?(hskupin) → review+
(In reply to Henrik Skupin (:whimboo) from comment #3)

> ::: testing/mozbase/rust/mozprofile/src/preferences.rs
> @@ +66,1 @@
> >  impl From<i64> for PrefValue {
> 
> Please put a short note below here why u64 doesn't work.

Converting from u64 _could_ work, but you’d need to make the return
type Result<PrefValue>, which I don’t think is a particularly good
idea.

> @@ +120,5 @@
> > +        assert_eq!(PrefValue::from(42u16), PrefValue::Int(42i64));
> > +        assert_eq!(PrefValue::from(42i32), PrefValue::Int(42i64));
> > +        assert_eq!(PrefValue::from(42u32), PrefValue::Int(42i64));
> > +        assert_eq!(PrefValue::from(42i64), PrefValue::Int(42i64));
> > +    }
> 
> Could we assert for an error in case of u64? Or will it refuse to compile?
> It might be the latter, right?

Correct, it will not compile because we don’t implement Into<Pref> for u64.
Pushed by atolfsen@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/0c727114d364
Provide more number conversions for mozprofile::preferences::PrefValue. r=whimboo
https://hg.mozilla.org/integration/mozilla-inbound/rev/c8fa2901262d
Avoid "as i64" coercion of marionette.port pref value. r=whimboo
https://hg.mozilla.org/mozilla-central/rev/0c727114d364
https://hg.mozilla.org/mozilla-central/rev/c8fa2901262d
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: