I definitely don't understand what's going on here; I need help understanding 2 things:
What the error is telling me.
How I should be able to do what I am trying to do
I am making a query and I'd like to see what the sql looks like before sending it and it looks like because there's a trait implementation for the type, that I should be able to just run the function associated, but apparently no?
Something like this seems like it should be possible, but I definitely don't understand a lot here. Docs: Query in sqlx::query - Rust
let q = sqlx::query("SELECT * FROM test WHERE item1 = $1)
.bind(test_item);
println!("{}",q.sql());
I am getting the error: items from traits can only be used if the trait is in scope
mod m {
pub trait Foo {
fn foo(&self) {}
}
impl Foo for () {
fn foo(&self) {}
}
}
fn f() {
().foo();
}
Compiling playground v0.0.1 (/playground)
error[E0599]: no method named `foo` found for unit type `()` in the current scope
--> src/lib.rs:11:8
|
3 | fn foo(&self) {}
| --- the method is available for `()` here
...
11 | ().foo();
| ^^^ method not found in `()`
|
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
1 | use crate::m::Foo;
|
For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to previous error
and hereās how to fix it
mod m {
pub trait Foo {
fn foo(&self) {}
}
impl Foo for () {
fn foo(&self) {}
}
}
+ use m::Foo;
+
fn f() {
().foo();
}
Also, as you can see, a full error message is significantly longer than what you posted, and the āitems from traits can only be used if the trait is in scopeā part is not even the error message at all, but merely a section of the additional āhelpā remarks the compiler gives. In case you need further help with the type and trait at hand, feel free to pose a complete error message as e.g. obtained by running cargo check from the terminal in the project directory
You can only call trait methods, e.g. .some_method(), when the corresponding trait is in scope, e.g. imported via use some_crate::SomeTrait (assuming that some_method is a method of SomeTrait).
If you paste the full error message, we might be able to help you in regard to which trait you missed to import.