Rust build with git projects or local projects not works

Hi Guys

I do not understand what's the difference when the dependences were retrieved from crates.io or github or local one.

Here are the 3 respective config in Cargo.toml

[dependencies]
piston = "0.27.0"
piston2d-graphics = "0.19.0"
pistoncore-glutin_window = "0.33.0"
piston2d-opengl_graphics = "0.36.0"
piston = {git = "https://github.com/PistonDevelopers/piston"}
piston2d-graphics = {git = "https://github.com/PistonDevelopers/graphics"}
pistoncore-glutin_window = {git = "https://github.com/PistonDevelopers/glutin_window"}
piston2d-opengl_graphics = {git = "https://github.com/PistonDevelopers/opengl_graphics"}
piston = {path="../piston-master"}
piston2d-graphics = {path="../graphics-master"}
pistoncore-glutin_window = {path="../glutin_window-master"}
piston2d-opengl_graphics = {path="../opengl_graphics-master"}

And the main.rs:

extern crate piston;
extern crate graphics;
extern crate glutin_window;
extern crate opengl_graphics;

use piston::window::WindowSettings;
use piston::event_loop::;
use piston::input::
;
use glutin_window::GlutinWindow;
use opengl_graphics::{GlGraphics, OpenGL};

pub struct App {
pub gl: GlGraphics, // OpenGL drawing backend.
pub rotation: f64, // Rotation for the square.
}

impl App {
pub fn render(&mut self, args: &RenderArgs) {
use graphics::*;

    const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0];
    const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0];

    let square = rectangle::square(0.0, 0.0, 50.0);
    let rotation = self.rotation;
    let (x, y) = ((args.width / 2) as f64, (args.height / 2) as f64);

    self.gl.draw(args.viewport(), |c, gl| {
        // Clear the screen.
        clear(GREEN, gl);

        let transform = c.transform
            .trans(x, y)
            .rot_rad(rotation)
            .trans(-25.0, -25.0);

        // Draw a box rotating around the middle of the screen.
        rectangle(RED, square, transform, gl);
    });
}

pub fn update(&mut self, args: &UpdateArgs) {
    // Rotate 2 radians per second.
    self.rotation += 2.0 * args.dt;
}

}

fn main() {
let opengl = OpenGL::V2_1;

// Create an Glutin window.
let mut window: GlutinWindow = WindowSettings::new("spinning-square", [200, 200])
    .opengl(opengl)
    .exit_on_esc(true)
    .build()
    .unwrap();

// Create a new game and run it.
let mut app = App {
    gl: GlGraphics::new(opengl),
    rotation: 0.0,
};

let mut events = window.events();
while let Some(e) = events.next(&mut window) {
    if let Some(r) = e.render_args() {
        app.render(&r);
    }

    if let Some(u) = e.update_args() {
        app.update(&u);
    }
}

}

When you try to build with dependences from crates.io, it will build successfully; whereas the rest 2 will have no luck.

I don't know why the rest 2 ways will fail, this is my first question.

And my second question is:

My purpose to build in the ways with dependences from github or local sources is: because the racer cannot show intelligent prompts for some methods or structs when I build with dependences from crates.io, I think it may due to the lacking of source files of the dependences, so I tried to build my project with source code from github or local projects instead of the crates from crates.io, in a hope to let racer show all the intelligent prompts. I don't know if I was in the wrong way or not, please give me a hand.

Much appreciated!

Well, often the source of packages on crates.io is also on github, but not always.

Crates.io has releases of software, that is, most projects ensure that they properly build, they have documentation, etc. If you solely ask for a dependency from github, you'll get whatever code happens to be on the default branch at the time. That code might not work. It might have changed its interface since the last time the docs were worked on. Etc.

This sounds like a mis-configuration or a bug in racer. Did you set CARGO_HOME?

1 Like

Very appreciate for your help!

Here is the Rusty Code Configuration from my VS Code's, I think I should specify the rust.cargoHomePath, but I don't know what it should be:

// Rusty Code configuration
// Specifies path to Racer binary if it's not in PATH
"rust.racerPath": "/usr/local/bin/racer",

// Specifies path to Rustfmt binary if it's not in PATH
"rust.rustfmtPath": "/usr/local/bin/rustfmt",

// Specifies path to Rustsym binary if it's not in PATH
"rust.rustsymPath": "/usr/local/bin/rustsym",

// Specifies path to /src directory of local copy of Rust sources
"rust.rustLangSrcPath": "/usr/local/src/rustc_src/src",

// Specifies path to Cargo binary if it's not in PATH
"rust.cargoPath": "/usr/local/bin/cargo",

// Specifies path to home directory of Cargo. Mostly needed for working with custom installations of Rust via rustup or multirust.
"rust.cargoHomePath": null,

// Specifies custom variables to set when running cargo. Useful for crates which use env vars in their build.rs (like openssl-sys).
"rust.cargoEnv": null,

// Turn on/off autoformatting file on save
"rust.formatOnSave": true,

// Turn on/off autochecking file on save using cargo check
"rust.checkOnSave": false,

// Choose between check, check-lib, clippy, build and test to lint
"rust.checkWith": "check",

// List of feature flags passed to cargo
"rust.features": [],

// Enable the use of JSON errors (requires Rust 1.7+). Note: This is an unstable feature of Rust and is still in the process of being stablised
"rust.useJsonErrors": false,

// Use the new Rust error format (RUST_NEW_ERROR_FORMAT=true). Note: This flag is mutually exclusive with `useJsonErrors`.
"rust.useNewErrorFormat": false

}