Error: can't find crate for 'iron'


#1

I have two issues when I run this example in my book <here>. When I ran cargo run it started doing the following…
image

ISSUE 1
As you can see it downloaded (or says it did) the crate iron v0.5.1. However, when I examine my main.rs file which I’m editing using SublimeText3 it shows the following warning (shown below) which is very weird since it downloaded and compiled my code. Why is sublime saying this error? Do I trust it? In sublime I installed this package called “Rust Enhanced” .
image

ISSUE 2
Lastly, whenever I go to my browser and type http://localhost:3000/gcd it just takes me to a blank page. This could easily be because I’m at work and doing this behind a firewall. However, I can still access the internet just fine.


#2

Just to make sure that the problem is on the editor’s side, can you show the full output of cargo run and re-run a cargo check cycle in sublime (via Tools > Build With > Rust-Enhanced - Check)?

When it comes to firewalls, note that they block connections port-wise and direction-wise. So if you have a software firewall running on your machine, it is well possible that you can surf the web (which mostly involves outgoing traffic on ports 80 and 443) without being able to connect to your iron server (listening to incoming traffic on port 3000). On the other hand, most companies use a networked firewall setup (where the firewall is not running on your machine, but on the company’s local network or at the local network <-> internet frontier), and these should not bother you because the localhost traffic stays local to your machine and does not go through them.

Out of curiosity, are you using Windows? It comes pre-installed with a basic firewall, which is on by default and blocks pretty much any incoming connection. But normally, it warns you when it does so by displaying a little dialog like “Hey, I blocked an incoming connection, do you want me to give it a pass?”.

Aside from this easy scenario, if the computer you are using has been set up by the company, they have added their own firewall software, and you don’t have admin rights, you may be out of luck…


#3

@HadrienG

[SublimeText Output]
Here is the output from running cargo-check. I didn’t even realize I could compile/run rust code in sublime.

click on arrow to expand
    [Running: cargo check --message-format=json]
       Compiling modifier v0.1.0
       Compiling httparse v1.2.4
       Compiling percent-encoding v1.0.1
       Compiling num-traits v0.1.42
       Compiling cfg-if v0.1.2
       Compiling libc v0.2.36
       Compiling typeable v0.1.2
       Compiling lazy_static v0.2.11
       Compiling serde v0.8.23
       Compiling matches v0.1.6
       Compiling rustc-serialize v0.3.24
       Compiling language-tags v0.2.2
       Compiling traitobject v0.1.0
       Compiling unicode-normalization v0.1.5
       Compiling itoa v0.1.1
       Compiling route-recognizer v0.1.12
       Compiling version_check v0.1.3
       Compiling byteorder v1.2.1
       Compiling dtoa v0.2.2
       Compiling safemem v0.2.0
       Compiling log v0.4.1
       Compiling num_cpus v1.8.0
       Compiling time v0.1.39
       Compiling unicode-bidi v0.3.4
       Compiling conduit-mime-types v0.7.3
       Compiling error v0.1.9
       Compiling unsafe-any v0.4.2
       Compiling unicase v1.4.2
       Compiling serde_json v0.8.6
       Compiling base64 v0.6.0
       Compiling log v0.3.9
       Compiling idna v0.1.4
       Compiling typemap v0.3.3
       Compiling mime v0.2.6
       Compiling plugin v0.2.6
       Compiling url v1.6.0
       Compiling hyper v0.10.13
       Compiling iron v0.5.1
       Compiling router v0.5.1
       Compiling persistent v0.3.0
       Compiling bodyparser v0.5.0
       Compiling urlencoded v0.5.0
       Compiling iron-gcd v0.1.0 (file:///export/home/syost/Rust/iron-gcd)
        Finished dev [unoptimized + debuginfo] target(s) in 15.57 secs 

[Terminal Output]
Here is the output from running cargo run from my terminal.

click on arrow to expand
       Compiling unicode-normalization v0.1.5
       Compiling typeable v0.1.2
       Compiling rustc-serialize v0.3.24
       Compiling matches v0.1.6
       Compiling libc v0.2.36
       Compiling itoa v0.1.1
       Compiling serde v0.8.23
       Compiling num-traits v0.1.42
       Compiling traitobject v0.1.0
       Compiling percent-encoding v1.0.1
       Compiling lazy_static v0.2.11
       Compiling dtoa v0.2.2
       Compiling byteorder v1.2.1
       Compiling route-recognizer v0.1.12
       Compiling cfg-if v0.1.2
       Compiling safemem v0.2.0
       Compiling modifier v0.1.0
       Compiling httparse v1.2.4
       Compiling language-tags v0.2.2
       Compiling unicode-bidi v0.3.4
       Compiling time v0.1.39
       Compiling num_cpus v1.8.0
       Compiling conduit-mime-types v0.7.3
       Compiling error v0.1.9
       Compiling unsafe-any v0.4.2
       Compiling serde_json v0.8.6
       Compiling log v0.4.1
       Compiling base64 v0.6.0
       Compiling idna v0.1.4
       Compiling typemap v0.3.3
       Compiling log v0.3.9
       Compiling plugin v0.2.6
       Compiling url v1.6.0
       Compiling unicase v1.4.2
       Compiling mime v0.2.6
       Compiling hyper v0.10.13
       Compiling iron v0.5.1
       Compiling persistent v0.3.0
       Compiling router v0.5.1
       Compiling bodyparser v0.5.0
       Compiling urlencoded v0.5.0
       Compiling iron-gcd v0.1.0 (file:///export/home/syost/Rust/iron-gcd)
        Finished dev [unoptimized + debuginfo] target(s) in 26.18 secs
         Running `target/debug/iron-gcd`
    Serving on http://localhost:3000...

As of now I’m not getting an error in sublime like I did before. I can also access http://localhost:3000 just fine now as well as view the complete functionality of this web server. I’m not sure what is different from today versus yesterday. I think our ITS emailed out a network issue that was going on so perhaps that was causing the error.

I have one last question. Say I have an application that uses crate xyz. If I develop another application down the road on the same computer that requires xyz will it have to go out and fetch this crate a second time? Say you are working on a computer that is inside a classified area where there is no internet as is a common thing at my place of work. How can I run a rust application in this case that has dependencies like crate xyz???


#4

Glad that the issue apparently resolved itself on its own :slight_smile: Happens sometimes!

Cargo can handle this kind of scenarios in various ways. Two examples:


#5

OT, but if you have text to dump, you can use <details> tags to hide it: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details.


#6

@derekdreery
Forgive my confusion, but would you be so kind in being a bit more descriptive in your reply. I have no idea what “OT” is being implied as or the implication of using HTML disclosure widgets or tags.


#7

Sorry, OT = “off topic”, since I’m talking about something not related to your post.

I was just letting you know about <details> in case you didn’t know about it.

If you write the following in this forum

<details>
<summary>Click on the arrow to expand me!</summary>
<pre>
These are the details
These are the details
These are the details
These are the details
These are the details
</pre>
</details>

you will get

Click on the arrow to expand me!
These are the details
These are the details
These are the details
These are the details
These are the details

which means you can dump config files or output without having it show up in the window :slight_smile:.


#8

@derekdreery means that, instead of posting a wall-of-text, such as your (very long) cargo output; it is polite to other forum-users (especially those on mobile phones) to put such long blocks of details in either an HTML <details> tag, or in Discourse’s “hide details” wrapper: [details="summary]HIDDEN[/details]

example

Lots of text


#9

@juleskers
@derekdreery
Thanks Guys for that clarification. I’ll be sure to incorporate this next time!


#10

TIL [details] :slight_smile:


#11

(before anyone else asks: TIL = “Today I Learned” :wink:)

You’re welcome! Discourse hides it under the :gear: menu, which I believe it hides by default for (very) new users.

@shanedora Thanks for improving your post :smiley: