Variable Types -

With this file, we're starting to look at data types.

It's not happy with line 7, where we tell it that we are going to be using a variable, x. It says, consider giving x a type, but let's be honest, when it says consider, it really means you have to.

But the thing is, you may recall that with, we never had to.

The thing is that previously, when we said that we were going to use a variable, we simultaneously assigned it. And when we assign it, Rust can make some inferences about what our intent is. In this example here, it's an integer.

So we are going to want. to do something like this:

With this syntax, we are saying, hey we want to use a variable x, it's going to be a signed 8-bit integer, and we are going to store 10 in it. There are a number of various integer types, and you can read all about them, in the Rust Programming Language's docs on Data Types.

Subscribe to Rust for Rubyists

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.