<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://programming.123web.uk/index.php?action=history&amp;feed=atom&amp;title=Rust_declare_variable</id>
	<title>Rust declare variable - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://programming.123web.uk/index.php?action=history&amp;feed=atom&amp;title=Rust_declare_variable"/>
	<link rel="alternate" type="text/html" href="https://programming.123web.uk/index.php?title=Rust_declare_variable&amp;action=history"/>
	<updated>2026-04-19T14:23:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://programming.123web.uk/index.php?title=Rust_declare_variable&amp;diff=9&amp;oldid=prev</id>
		<title>Dylan: create Rust declare variable</title>
		<link rel="alternate" type="text/html" href="https://programming.123web.uk/index.php?title=Rust_declare_variable&amp;diff=9&amp;oldid=prev"/>
		<updated>2025-08-07T15:24:57Z</updated>

		<summary type="html">&lt;p&gt;create Rust declare variable&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Declaring a variable ==&lt;br /&gt;
The syntax for declaring variables in Rust is:&amp;lt;syntaxhighlight lang=&amp;quot;rust&amp;quot;&amp;gt;&lt;br /&gt;
let VARIABLE_NAME: TYPE;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;The &amp;lt;code&amp;gt;VARIABLE_NAME&amp;lt;/code&amp;gt; should be set to any alpha-numerical string, and can also include underscores. See [[naming variables]] for a guide on how to name variables, and [[Rust identifier naming conventions]] for advice on common conventions.&lt;br /&gt;
&lt;br /&gt;
=== Example of declaring a variable ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rust&amp;quot;&amp;gt;&lt;br /&gt;
let name: String;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Declare and initialize together ==&lt;br /&gt;
You can also both create (declare) and initialize (set the value of) a variable in one line:&amp;lt;syntaxhighlight lang=&amp;quot;rust&amp;quot;&amp;gt;&lt;br /&gt;
let VARIABLE_NAME: TYPE = VALUE;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;There is more info on initializing variables in Rust on the [[Rust initialize variable]] page.&lt;br /&gt;
&lt;br /&gt;
=== Example of declaring and initializing a variable ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rust&amp;quot;&amp;gt;&lt;br /&gt;
let town: &amp;amp;str = &amp;quot;Paris&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Type inference ==&lt;br /&gt;
The Rust compiler is clever enough to &amp;#039;&amp;#039;infer&amp;#039;&amp;#039; the type of a variable based on the value we assign it.&lt;br /&gt;
&lt;br /&gt;
We still need to give it a value at some point, otherwise it&amp;#039;s impossible for the compiler to know what type to give it.&lt;br /&gt;
&lt;br /&gt;
=== Example of type inference ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rust&amp;quot;&amp;gt;&lt;br /&gt;
let age = 21;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;In this example, the compiler will &amp;#039;&amp;#039;infer&amp;#039;&amp;#039; that the type of &amp;lt;code&amp;gt;age&amp;lt;/code&amp;gt; is an &amp;lt;code&amp;gt;i32&amp;lt;/code&amp;gt;, a signed 32-bit integer (number).&lt;/div&gt;</summary>
		<author><name>Dylan</name></author>
	</entry>
</feed>