Open manortec opened 2 months ago
Hi. This is because Row::get
by itself returns an Option
, so if cell type is Option<String>
, then the return type of the get function is Option<Option<String>>
.
Btw, I would call the get
function low level, try something like this instead:
let Some((guid_user, nick_name, email, phone)) = conn.exec_first(q,p).await? else {
return Ok(None);
};
Ok(UserInfo {
guid_user,
nick_name,
email,
phone,
});
Hi. This is because
Row::get
by itself returns anOption
, so if cell type isOption<String>
, then the return type of the get function isOption<Option<String>>
. Btw, I would call theget
function low level, try something like this instead:let Some((guid_user, nick_name, email, phone)) = conn.exec_first(q,p).await? else { return Ok(None); }; Ok(UserInfo { guid_user, nick_name, email, phone, });
Thank you very much! I will have a try.
I'm writing a web application,and I encountered a problem when using mysql_async. I found that the get or take method of the Row type(Row.get(index))could not correctly convert the Null value to the expected type "None", but other non-Null values could be converted well. The following is my relevant code. This code can be compiled, but a panic error will occur when running this code. At the same time, I also listed a code that can run correctly for comparison. Thank you very much for any help.
When I make a request calling this function, I get the following error:
It should be noted that the fields nick_name and email in my database have null values, and other fields have normal values. As a comparison test, if you replace the two lines below with the two commented out lines in the above code, it will run correctly. For another comparison, if the nick_name and email fields are filled with normal values, or the query does not contain fields with null values, the above code can also run correctly. The result of a correctly executed request is roughly like this.
The mysql_async version used in my cargo.toml file is as follows:
The result I expect is that if the type of a certain attribute of my structure is Option (T), then the get or take method of the Row type needs to convert the null value to None. Thank you very much for your answer.