Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option::<bool>::from_value_opt behavior #148

Closed
wqfish opened this issue Feb 19, 2021 · 2 comments
Closed

Option::<bool>::from_value_opt behavior #148

wqfish opened this issue Feb 19, 2021 · 2 comments

Comments

@wqfish
Copy link

wqfish commented Feb 19, 2021

The following code prints Some(true).

let value = Value::Int(1);
let out = Option::<bool>::from_value_opt(value).unwrap();
println!("{:?}", out);

The following code panics:

let value = Value::UInt(1);
let out = Option::<bool>::from_value_opt(value).unwrap();
println!("{:?}", out)

Is it expected that Int(1) can be converted to Option<bool> while UInt(1) can't?

BTW I'm on version 0.25. The newer versions fail to compile (a bunch of tokio errors):

    Updating crates.io index
   Compiling mysql_async v0.26.0
error[E0425]: cannot find function `spawn` in crate `tokio`
  --> /Users/wqfish/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/mysql_async-0.26.0/src/conn/pool/ttl_check_inerval.rs:59:24
   |
59 |                 tokio::spawn(idling_conn.conn.disconnect().then(move |_| {
   |                        ^^^^^ not found in `tokio`
   |
help: consider importing one of these items
   |
9  | use crate::conn::pool::mpsc::list::thread::spawn;
   |
9  | use std::thread::spawn;
   |
@blackbeam
Copy link
Owner

Hi, @wqfish.

Is it expected that Int(1) can be converted to Option<bool> while UInt(1) can't?

This behavior is explicitly stated in the docs (see the table here). Did you get this value from the server or it was created artificially?

Note that you should never get boolean value from the server as Value::UInt(1), even if it's declared as TINYINT(1) UNSIGNED.

BTW I'm on version 0.25. The newer versions fail to compile (a bunch of tokio errors)

Oh, thanks for pointing this out! CI couldn't catch this because of a bug in cargo (see rust-lang/cargo#1796). Please use v0.26.1 or v0.27.1.

@wqfish
Copy link
Author

wqfish commented Feb 21, 2021

Ah just artificial values. I'll look into the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants