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

Troubles compiling the given example select query #35

Closed
d3v3lop3rDE opened this issue May 17, 2021 · 3 comments
Closed

Troubles compiling the given example select query #35

d3v3lop3rDE opened this issue May 17, 2021 · 3 comments

Comments

@d3v3lop3rDE
Copy link

d3v3lop3rDE commented May 17, 2021

I can't compile your example with these errors:

error[E0277]: the ? operator can only be used in a function that returns Result or Option (or another type that implements Try)
--> src\main.rs:7:16
|
4 | / fn main() {
5 | |
6 | | // Connect to a database.
7 | | let conn = Connection::connect("scott", "tiger", "//localhost/XE")?;
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot use the ? operator in a function that returns ()
... |
29 | | }
30 | | }
| |_- this function should return Result or Option to accept ?
|
= help: the trait Try is not implemented for ()
= note: required by from_error

error[E0277]: the ? operator can only be used in a function that returns Result or Option (or another type that implements Try)
--> src\main.rs:13:16
|
4 | / fn main() {
5 | |
6 | | // Connect to a database.
7 | | let conn = Connection::connect("scott", "tiger", "//localhost/XE")?;
... |
13 | | let rows = conn.query(sql, &[&30])?;
| | ^^^^^^^^^^^^^^^^^^^^^^^^ cannot use the ? operator in a function that returns ()
... |
29 | | }
30 | | }
| |_- this function should return Result or Option to accept ?
|
= help: the trait Try is not implemented for ()
= note: required by from_error

error[E0277]: the ? operator can only be used in a function that returns Result or Option (or another type that implements Try)
--> src\main.rs:15:19
|
4 | / fn main() {
5 | |
6 | | // Connect to a database.
7 | | let conn = Connection::connect("scott", "tiger", "//localhost/XE")?;
... |
15 | | let row = row_result?;
| | ^^^^^^^^^^^ cannot use the ? operator in a function that returns ()
... |
29 | | }
30 | | }
| |_- this function should return Result or Option to accept ?
|
= help: the trait Try is not implemented for ()
= note: required by from_error

error[E0277]: the ? operator can only be used in a function that returns Result or Option (or another type that implements Try)
--> src\main.rs:17:29
|
4 | / fn main() {
5 | |
6 | | // Connect to a database.
7 | | let conn = Connection::connect("scott", "tiger", "//localhost/XE")?;
... |
17 | | let ename: String = row.get(0)?;
| | ^^^^^^^^^^^ cannot use the ? operator in a function that returns ()
... |
29 | | }
30 | | }
| |_- this function should return Result or Option to accept ?
|
= help: the trait Try is not implemented for ()
= note: required by from_error

error[E0277]: the ? operator can only be used in a function that returns Result or Option (or another type that implements Try)
--> src\main.rs:19:24
|
4 | / fn main() {
5 | |
6 | | // Connect to a database.
7 | | let conn = Connection::connect("scott", "tiger", "//localhost/XE")?;
... |
19 | | let sal: i32 = row.get("sal")?;
| | ^^^^^^^^^^^^^^^ cannot use the ? operator in a function that returns ()
... |
29 | | }
30 | | }
| |_- this function should return Result or Option to accept ?
|
= help: the trait Try is not implemented for ()
= note: required by from_error

error[E0277]: the ? operator can only be used in a function that returns Result or Option (or another type that implements Try)
--> src\main.rs:23:33
|
4 | / fn main() {
5 | |
6 | | // Connect to a database.
7 | | let conn = Connection::connect("scott", "tiger", "//localhost/XE")?;
... |
23 | | let comm: Option = row.get(2)?;
| | ^^^^^^^^^^^ cannot use the ? operator in a function that returns ()
... |
29 | | }
30 | | }
| |_- this function should return Result or Option to accept ?
|
= help: the trait Try is not implemented for ()
= note: required by from_error

error: aborting due to 6 previous errors; 1 warning emitted

I am using Rust 1.52.1

@kubo
Copy link
Owner

kubo commented May 17, 2021

You need to learn error handling. Especially this section.

@kubo
Copy link
Owner

kubo commented May 17, 2021

Examples use ? to follow this API guideline.

@kubo kubo closed this as completed May 17, 2021
@d3v3lop3rDE
Copy link
Author

Thank you! 🙈

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