Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upExample from README is not working #36
Comments
This comment has been minimized.
|
Are you |
This comment has been minimized.
defyrlt
commented
Nov 30, 2015
|
That's the full code. I thought that #![feature(custom_derive)]
#[macro_use]
extern crate diesel;
use diesel::*;
table! {
users {
id -> Serial,
name -> VarChar,
favorite_color -> Nullable<VarChar>,
}
}
#[derive(Queriable, Debug)]
pub struct User {
id: i32,
name: String,
favorite_color: Option<String>,
}
fn main() {
let connection = Connection::establish(env!("DATABASE_URL"))
.unwrap();
let users: Vec<User> = users::table.load(&connection)
.unwrap().collect();
println!("Here are all the users in our database: {:?}", users);
}src/main.rs:27:19: 27:28 error: the trait `diesel::query_source::Queriable<(diesel::types::Integer, diesel::types::VarChar, diesel::types::Nullable<diesel::types::VarChar>)>` is not implemented for the type `User` [E0277]
src/main.rs:27 .unwrap().collect();
^~~~~~~~~
src/main.rs:27:19: 27:28 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:26:41: 26:58 error: the trait `diesel::query_source::Queriable<(diesel::types::Integer, diesel::types::VarChar, diesel::types::Nullable<diesel::types::VarChar>)>` is not implemented for the type `User` [E0277]
src/main.rs:26 let users: Vec<User> = users::table.load(&connection)
^~~~~~~~~~~~~~~~~
src/main.rs:26:41: 26:58 help: run `rustc --explain E0277` to see a detailed explanation
error: aborting due to 2 previous errors
Could not compile `try_diesel`. |
This comment has been minimized.
|
Deriving should be enough. Have you followed the instructions at https://github.com/sgrif/diesel/blob/master/diesel_codegen/README.md#using-on-nightly? This looks like you're probably just missing the |
This comment has been minimized.
defyrlt
commented
Nov 30, 2015
|
If I don't use [dependencies]
diesel = "*"
diesel_codegen = { version = "^0.1.0", default-features = false, features = ["nightly"] }#![feature(custom_derive, custom_attribute, plugin)]
#![plugin(diesel_codegen)]
#[macro_use]
extern crate diesel;
extern crate diesel_codegen;
use diesel::*; Compiling aster v0.8.0
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:950:35: 950:52 error: use of undeclared type name `ast::ImplItemKind` [E0412]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:950 pub fn build_item(self, node: ast::ImplItemKind) -> F::Result {
^~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:950:35: 950:52 help: run `rustc --explain E0412` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:979:20: 979:44 error: failed to resolve. Could not find `ImplItemKind` in `syntax::ast` [E0433]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:979 let node = ast::ImplItemKind::Const(const_.ty, const_.expr.expect("an expr is required for a const impl item"));
^~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:979:20: 979:44 help: run `rustc --explain E0433` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:979:20: 979:44 error: unresolved name `ast::ImplItemKind::Const` [E0425]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:979 let node = ast::ImplItemKind::Const(const_.ty, const_.expr.expect("an expr is required for a const impl item"));
^~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:979:20: 979:44 help: run `rustc --explain E0425` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:990:20: 990:45 error: failed to resolve. Could not find `ImplItemKind` in `syntax::ast` [E0433]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:990 let node = ast::ImplItemKind::Method(method.sig, method.block.expect("a block is required for a method impl item"));
^~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:990:20: 990:45 help: run `rustc --explain E0433` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:990:20: 990:45 error: unresolved name `ast::ImplItemKind::Method` [E0425]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:990 let node = ast::ImplItemKind::Method(method.sig, method.block.expect("a block is required for a method impl item"));
^~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:990:20: 990:45 help: run `rustc --explain E0425` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1001:20: 1001:43 error: failed to resolve. Could not find `ImplItemKind` in `syntax::ast` [E0433]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1001 let node = ast::ImplItemKind::Type(ty);
^~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1001:20: 1001:43 help: run `rustc --explain E0433` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1001:20: 1001:43 error: unresolved name `ast::ImplItemKind::Type` [E0425]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1001 let node = ast::ImplItemKind::Type(ty);
^~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1001:20: 1001:43 help: run `rustc --explain E0425` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1012:20: 1012:44 error: failed to resolve. Could not find `ImplItemKind` in `syntax::ast` [E0433]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1012 let node = ast::ImplItemKind::Macro(mac);
^~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1012:20: 1012:44 help: run `rustc --explain E0433` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1012:20: 1012:44 error: unresolved name `ast::ImplItemKind::Macro` [E0425]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1012 let node = ast::ImplItemKind::Macro(mac);
^~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1012:20: 1012:44 help: run `rustc --explain E0425` to see a detailed explanation
error: aborting due to 9 previous errors
Could not compile `aster`.And I make it src/main.rs:29:19: 29:28 error: the trait `diesel::query_source::Queriable<(diesel::types::Integer, diesel::types::VarChar, diesel::types::Nullable<diesel::types::VarChar>)>` is not implemented for the type `User` [E0277]
src/main.rs:29 .unwrap().collect();
^~~~~~~~~
src/main.rs:29:19: 29:28 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:28:41: 28:58 error: the trait `diesel::query_source::Queriable<(diesel::types::Integer, diesel::types::VarChar, diesel::types::Nullable<diesel::types::VarChar>)>` is not implemented for the type `User` [E0277]
src/main.rs:28 let users: Vec<User> = users::table.load(&connection)
^~~~~~~~~~~~~~~~~
src/main.rs:28:41: 28:58 help: run `rustc --explain E0277` to see a detailed explanation
error: aborting due to 2 previous errors
Could not compile `try_diesel`. |
This comment has been minimized.
|
I should probably make it more clear in the README, |
This comment has been minimized.
defyrlt
commented
Nov 30, 2015
|
Got latest nightly. It works! Sorry, I should've done this before. |
This comment has been minimized.
|
The problem is that the type of your struct can very much not be one-to-one with the types of the table. I am planning on eventually adding |
This comment has been minimized.
defyrlt
commented
Nov 30, 2015
|
How about marking fields like this? #[derive(Queriable, Debug)]
pub struct User {
#[column_type = Serial]
id: i32,
#[column_type = VarChar]
name: String,
}UPD: this particular issue is closed. Let's make another one for automatic generation of |
defyrlt commentedNov 30, 2015
I'm trying this example from the README (added some imports from previous one with
table!macro):Here's my error msg:
rustc: