构建Rocket车把示例时未解决的导入模板

时间:2017-06-04 08:48:05

标签: rust rust-rocket

我无法获得火箭handlebars example 上班。这些是我的Cargo.toml依赖项:

try {

        Session session = factory.getCurrentSession();

        session.beginTransaction();
        Query query = session.createQuery("select uName1,pass1 from UserRegModel");

        List<Object> userList = new ArrayList<Object>();

        userList = query.getResultList();

        System.out.println("selecting usernaem and pass done");

        for (Object temp : userList) {

            System.out.println(temp);
        }

        session.getTransaction().commit();

        return userList;

    } catch (Exception e) {
        System.out.println(e);
    }

错误:

[dependencies]
rocket = "*"
rocket_codegen = "*"
rocket_contrib = "*"
serde = "*"
serde_json = "*"
serde_derive = "*"

第一个错误查找error[E0432]: unresolved import `rocket_contrib::Template` --> src\main.rs:29:5 | 29 | use rocket_contrib::Template; | ^^^^^^^^^^^^^^^^^^^^^^^^ no `Template` in the root error[E0599]: no method named `attach` found for type `rocket::Rocket` in the current scope --> src\main.rs:62:10 | 62 | .attach(Template::fairing()) | ^^^^^^ 但无法找到它。在示例的git repo中,它不存在。该示例如何工作?我确信我的main.rs中的Rust代码没问题,它与示例中的相同。我认为这只是一个依赖性问题。

我将Cargo.toml改为:

Template

现在我收到了这些错误:

[dependencies]
rocket = "*"
rocket_codegen = "*"
serde = "*"
serde_json = "*"
serde_derive = "*"

[dependencies.rocket_contrib]
version = "*"
features = ["handlebars_templates"]

1 个答案:

答案 0 :(得分:5)

您缺少handlebars_templates功能。你可以see this in the example's Cargo.toml

[dependencies.rocket_contrib]
version = "*" # Not a good idea to use * as version
features = ["handlebars_templates"]