<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rust | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/category/rust/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Sat, 26 Apr 2025 14:24:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>Rust | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Debugging C/C++ and Rust with codelldb</title>
		<link>https://learncgames.com/debugging-c-c-and-rust-with-codelldb/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=debugging-c-c-and-rust-with-codelldb</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 26 Apr 2025 23:05:03 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Rust]]></category>
		<category><![CDATA[debugging]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3381</guid>

					<description><![CDATA[<p>As a user of Visual Studio since about VS 5, I&#8217;ve become accustomed to being able to debug. With VS Code, it&#8217;s also been easy but now that I program in C and Rust, the codelldb extension makes things very easy. You need other extensions: for Rust- the Rust Analyzer extension and for C/C++ the [&#8230;]</p>
The post <a href="https://learncgames.com/debugging-c-c-and-rust-with-codelldb/">Debugging C/C++ and Rust with codelldb</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" class="alignleft size-full wp-image-3385" src="https://learncgames.com/wp-content/uploads/2025/04/extensions.png" alt="Extensions for C/C++" width="350" height="562" srcset="https://learncgames.com/wp-content/uploads/2025/04/extensions.png 350w, https://learncgames.com/wp-content/uploads/2025/04/extensions-187x300.png 187w" sizes="(max-width: 350px) 100vw, 350px" />As a user of Visual Studio since about VS 5, I&#8217;ve become accustomed to being able to debug. With VS Code, it&#8217;s also been easy but now that I program in C and Rust, the <strong>codelldb</strong> extension makes things very easy. You need other extensions: for Rust- the Rust Analyzer extension and for C/C++ the Microsoft C/C++ extension.</p>
<p>And for debugging for both the codelldb extension which is shown.  It uses the usual Microsoft debugging keys: F5 to start F10 to step over, F11 to step into and F9 to toggle a breakpoint.</p>
<p>Below is an example of debugging a Rust program.</p>
<p><img decoding="async" class="alignleft size-full wp-image-3386" src="https://learncgames.com/wp-content/uploads/2025/04/debuggingRust.png" alt="debugging Rust program in VS Code" width="1094" height="557" srcset="https://learncgames.com/wp-content/uploads/2025/04/debuggingRust.png 1094w, https://learncgames.com/wp-content/uploads/2025/04/debuggingRust-300x153.png 300w, https://learncgames.com/wp-content/uploads/2025/04/debuggingRust-1024x521.png 1024w, https://learncgames.com/wp-content/uploads/2025/04/debuggingRust-768x391.png 768w" sizes="(max-width: 1094px) 100vw, 1094px" /></p>The post <a href="https://learncgames.com/debugging-c-c-and-rust-with-codelldb/">Debugging C/C++ and Rust with codelldb</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3381</post-id>	</item>
		<item>
		<title>Rust on Windows &#8211; problem with sdl2.lib</title>
		<link>https://learncgames.com/rust-on-windows-problem-with-sdl2-lib/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rust-on-windows-problem-with-sdl2-lib</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 06 Apr 2025 12:59:46 +0000</pubDate>
				<category><![CDATA[bugs]]></category>
		<category><![CDATA[Rust]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[compile error]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[SDL2]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3364</guid>

					<description><![CDATA[<p>I&#8217;m currently unable to compile Rust programs that use SDL2 on Windows. No problems on Ubuntu or Raspberry Pi OS, just Windows 11. Although it says cannot open input file SDL2.lib, I think the problem is a parameter passed into Link.exe. The text from the image above is listed below- I&#8217;ve broken it to make [&#8230;]</p>
The post <a href="https://learncgames.com/rust-on-windows-problem-with-sdl2-lib/">Rust on Windows – problem with sdl2.lib</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>I&#8217;m currently unable to compile Rust programs that use SDL2 on Windows. No problems on Ubuntu or Raspberry Pi OS, just Windows 11.<br />
<img decoding="async" class="alignleft size-large wp-image-3365" src="https://learncgames.com/wp-content/uploads/2025/04/compiling_sdl2_on_windows-1024x174.png" alt="Compiling an SDL2 app (in Rust) on Windows" width="1024" height="174" srcset="https://learncgames.com/wp-content/uploads/2025/04/compiling_sdl2_on_windows-1024x174.png 1024w, https://learncgames.com/wp-content/uploads/2025/04/compiling_sdl2_on_windows-300x51.png 300w, https://learncgames.com/wp-content/uploads/2025/04/compiling_sdl2_on_windows-768x130.png 768w, https://learncgames.com/wp-content/uploads/2025/04/compiling_sdl2_on_windows.png 1213w" sizes="(max-width: 1024px) 100vw, 1024px" />Although it says cannot open input file SDL2.lib, I think the problem is a parameter passed into Link.exe.</p>
<p>The text from the image above is listed below- I&#8217;ve broken it to make it readable as it&#8217;s displayed preformatted and unmodified it is all on a single very wide line!</p>
<pre> = note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.43.34808\\bin\\HostX64\\x64\\link.exe" 
"/NOLOGO" "C:\\Users\\dhbol\\AppData\\Local\\Temp\\rustcA1PhoK\\symbols.o" "&lt;70 object files omitted&gt;" 
"D:\\development\\rustapps\\choice\\target\\debug\\deps/{libsdl2-f8d94d30d19bed49.rlib,libsdl2_sys-325e30d8e9547ff4.rlib,
libbitflags-d15393d08e2f31fc.rlib,liblazy_static-c28c0e13093a4168.rlib,liblibc-851e0bf801239f69.rlib}.rlib" 
"&lt;sysroot&gt;\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib/{libstd-*,libpanic_unwind-*,libwindows_targets-*,
librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libunwind-*,libcfg_if-*,liballoc-*,
librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "SDL2.lib" "SDL2_image.lib" "SDL2_ttf.lib" 
"legacy_stdio_definitions.lib" "kernel32.lib" "kernel32.lib" "advapi32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" 
"dbghelp.lib" "/defaultlib:msvcrt" "/NXCOMPAT" "/OUT:D:\\development\\rustapps\\choice\\target\\debug\\deps\\choice.exe" 
"/OPT:REF,NOICF" "/DEBUG" "/PDBALTPATH:%_PDB%" "/NATVIS:&lt;sysroot&gt;\\lib\\rustlib\\etc\\intrinsic.natvis" 
"/NATVIS:&lt;sysroot&gt;\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:&lt;sysroot&gt;\\lib\\rustlib\\etc\\libcore.natvis" 
"/NATVIS:&lt;sysroot&gt;\\lib\\rustlib\\etc\\libstd.natvis"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: LINK : fatal error LNK1181: cannot open input file 'SDL2.lib'␍</pre>
<p>But if you try running part of it like the first line<br />
&#8220;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.43.34808\\bin\\HostX64\\x64\\link.exe&#8221;<br />
&#8220;/NOLOGO&#8221; &#8220;C:\\Users\\dhbol\\AppData\\Local\\Temp\\rustcA1PhoK\\symbols.o&#8221;</p>
<p>Well the path to link..exe is correct, but there&#8217;s no  rustcA1PhoK\symbols.o in that temp folder. Any suggestions welcomed&#8230;</p>
<h2>I just solved it.</h2>
<p>I&#8217;ve left this in, in case anyone else has this problem.</p>
<p>You need to add an environment variable LIB with the address of the SDL .lib files including ttf, image and mixer. Make sure they&#8217;re all in this folder:</p>
<p>C:\Users\<strong>dhbol</strong>\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib</p>
<p>The bold part of the path will be different on you PC.</p>
<p>In File Explorer, right-click on <strong>This PC </strong>then click Properties on the popup menu.</p>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3372" src="https://learncgames.com/wp-content/uploads/2025/04/this_pc.png" alt="File Explorer - This PC,." width="170" height="70" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>It&#8217;ll open Settings &#8211; About, and you need to click <strong>Advanced system settings</strong>.</p>
<p><img loading="lazy" decoding="async" class="alignleft size-medium wp-image-3374" src="https://learncgames.com/wp-content/uploads/2025/04/settings_about-300x154.png" alt="settings_about" width="300" height="154" srcset="https://learncgames.com/wp-content/uploads/2025/04/settings_about-300x154.png 300w, https://learncgames.com/wp-content/uploads/2025/04/settings_about.png 600w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>This opens System Properties and on that you click <strong>Environment variables</strong>.</p>
<p><img loading="lazy" decoding="async" class="alignleft size-medium wp-image-3375" src="https://learncgames.com/wp-content/uploads/2025/04/System_properties-264x300.png" alt="System properties on Windows" width="264" height="300" srcset="https://learncgames.com/wp-content/uploads/2025/04/System_properties-264x300.png 264w, https://learncgames.com/wp-content/uploads/2025/04/System_properties.png 412w" sizes="auto, (max-width: 264px) 100vw, 264px" /></p>
<p><img loading="lazy" decoding="async" class="alignleft wp-image-3376 size-full" src="https://learncgames.com/wp-content/uploads/2025/04/environment_variables.png" alt="Environment variables popup on Windows" width="646" height="585" srcset="https://learncgames.com/wp-content/uploads/2025/04/environment_variables.png 646w, https://learncgames.com/wp-content/uploads/2025/04/environment_variables-300x272.png 300w" sizes="auto, (max-width: 646px) 100vw, 646px" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Now just click New and add Lib and that path It should look something like mine. Now reopen Visual Studio and your SDL2 Rust app should now build and run.</p>The post <a href="https://learncgames.com/rust-on-windows-problem-with-sdl2-lib/">Rust on Windows – problem with sdl2.lib</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3364</post-id>	</item>
		<item>
		<title>How fast is a Raspberry Pi 5?</title>
		<link>https://learncgames.com/how-fast-is-a-raspberry-pi-5/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-fast-is-a-raspberry-pi-5</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Tue, 18 Mar 2025 00:05:10 +0000</pubDate>
				<category><![CDATA[64-bit]]></category>
		<category><![CDATA[raspberry-pi]]></category>
		<category><![CDATA[Rust]]></category>
		<category><![CDATA[poker]]></category>
		<category><![CDATA[speed]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3340</guid>

					<description><![CDATA[<p>I recently bought one with 8 GB RAM pictured above. I haven&#8217;t got an SSD for it yet so am still pottering about with an SD Card. I&#8217;ve installed VS Code, clang. and Rust along with the VS Code extensions Rust-Analyzer and codelldb. Out of curiosity I compiled and ran a Rust program that reads [&#8230;]</p>
The post <a href="https://learncgames.com/how-fast-is-a-raspberry-pi-5/">How fast is a Raspberry Pi 5?</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:20,&quot;href&quot;:&quot;https:\/\/github.com\/David-H-Bolton\/Projects\/blob\/main\/rust_pokerhand_faster.zip&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3341" src="https://learncgames.com/wp-content/uploads/2025/03/raspi-5.png" alt="Raspberry PI 5" width="606" height="402" srcset="https://learncgames.com/wp-content/uploads/2025/03/raspi-5.png 606w, https://learncgames.com/wp-content/uploads/2025/03/raspi-5-300x199.png 300w" sizes="auto, (max-width: 606px) 100vw, 606px" />I recently bought one with 8 GB RAM pictured above. I haven&#8217;t got an SSD for it yet so am still pottering about with an SD Card.</p>
<p>I&#8217;ve installed VS Code, clang. and Rust along with the VS Code extensions Rust-Analyzer and codelldb.</p>
<p>Out of curiosity I compiled and ran a Rust program that reads in a text file of 1,000 lines of text with each line holding 7 random cards like this: AH 6D 2C 4S JD QH QC.</p>
<p>The idea is to load the file into RAM then process each line and determine the best poker hand.</p>
<p>On my PC 11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz (which runs Windows 11), I compared running the Rust program in Windows 11, on Ubuntu 24.04 LTS running in a Hyper-V VM on the same PC and on the Raspberry Pi 5 using it&#8217;s own Debian (Bookworm) version.</p>
<p>Here are the times per hand.</p>
<ul>
<li><strong>Windows</strong>: 175 ns.</li>
<li><strong>Ubuntu on Hyper-V</strong> 125 ns</li>
<li><strong>Raspberry Pi 5</strong>: 175 ns.</li>
</ul>
<p>You can download the project with the test cards from <a title="Download Rust project zip file from GitHub" href="https://github.com/David-H-Bolton/Projects/blob/main/rust_pokerhand_faster.zip">GitHub</a>. This link is a zip file containing the project file.</p>
<p>To run it in release in VS Code, in the terminal type in</p>
<pre>cargo run --release 1000_card_hands.txt</pre>
<pre><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3342" src="https://learncgames.com/wp-content/uploads/2025/03/timings.png" alt="Timings running under Ubuntu" width="710" height="90" srcset="https://learncgames.com/wp-content/uploads/2025/03/timings.png 710w, https://learncgames.com/wp-content/uploads/2025/03/timings-300x38.png 300w" sizes="auto, (max-width: 710px) 100vw, 710px" /></pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Or you can view the test cards which include the results with commemts in the test file. No need to run it release.</p>
<pre>cargo run --features=show_cards test_card_hands.txt

<img loading="lazy" decoding="async" class="alignleft size-full wp-image-3344" src="https://learncgames.com/wp-content/uploads/2025/03/showcards.png" alt="Showing cards with test data" width="815" height="431" srcset="https://learncgames.com/wp-content/uploads/2025/03/showcards.png 815w, https://learncgames.com/wp-content/uploads/2025/03/showcards-300x159.png 300w, https://learncgames.com/wp-content/uploads/2025/03/showcards-768x406.png 768w" sizes="auto, (max-width: 815px) 100vw, 815px" />
</pre>
<p>What is so suprising is that the time on Windows and Rapberry Pi 5 are the same. Windows is running a virus checker (Windows Defender) and I guess that might slow it a bit. </p>The post <a href="https://learncgames.com/how-fast-is-a-raspberry-pi-5/">How fast is a Raspberry Pi 5?</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3340</post-id>	</item>
		<item>
		<title>So I bought a Raspberry PI 5 and VS Code crashes!</title>
		<link>https://learncgames.com/so-i-bought-a-raspberry-pi-5-and-vs-code-crashes/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=so-i-bought-a-raspberry-pi-5-and-vs-code-crashes</link>
					<comments>https://learncgames.com/so-i-bought-a-raspberry-pi-5-and-vs-code-crashes/#comments</comments>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 09 Mar 2025 00:05:21 +0000</pubDate>
				<category><![CDATA[bugs]]></category>
		<category><![CDATA[Rust]]></category>
		<category><![CDATA[Visual Studio Code]]></category>
		<category><![CDATA[crash]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3330</guid>

					<description><![CDATA[<p>And the first thing I did after assembling it, was install VS Code and Rust.  And irritatingly, there&#8217;s some kind of a bug with the current version of VS Code. 1.97. Open a project- say for a Rust application and view the source code. After a few seconds or so it crashes with a The [&#8230;]</p>
The post <a href="https://learncgames.com/so-i-bought-a-raspberry-pi-5-and-vs-code-crashes/">So I bought a Raspberry PI 5 and VS Code crashes!</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3332" src="https://learncgames.com/wp-content/uploads/2025/03/crash.png" alt="Crash on VS Code running on a Reaspberry Pi 5." width="606" height="208" srcset="https://learncgames.com/wp-content/uploads/2025/03/crash.png 606w, https://learncgames.com/wp-content/uploads/2025/03/crash-300x103.png 300w" sizes="auto, (max-width: 606px) 100vw, 606px" /></p>
<p>And the first thing I did after assembling it, was install VS Code and Rust.  And irritatingly, there&#8217;s some kind of a bug with the current version of VS Code. 1.97.</p>
<p>Open a project- say for a Rust application and view the source code. After a few seconds or so it crashes with a <strong>The window terminated unexpectedly (reason: &#8216;crashed&#8217;, code 5).</strong></p>
<p>I also updated my Raspberry Pi 4B, installed Rust and got the same crash with it.</p>
<p>Thankfully Raspis come with <strong>grim</strong> which lets you do screenshots on Wayland.</p>
<p>Want to know if your system is running Wayland? From a terminal run this command:</p>
<p>echo &#8220;$XDG_SESSION_TYPE&#8221;</p>
<p>And you&#8217;ll either get <em>wayland</em> or <em>x11</em>.</p>
<p>So I hope the VS Code issue gets fixed soon.</p>The post <a href="https://learncgames.com/so-i-bought-a-raspberry-pi-5-and-vs-code-crashes/">So I bought a Raspberry PI 5 and VS Code crashes!</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://learncgames.com/so-i-bought-a-raspberry-pi-5-and-vs-code-crashes/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3330</post-id>	</item>
		<item>
		<title>Bit of a curiosity &#8211; Rust runs slower on Windows than Linux</title>
		<link>https://learncgames.com/bit-of-a-curiosity-rust-runs-slower-on-windows-than-linux/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bit-of-a-curiosity-rust-runs-slower-on-windows-than-linux</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Fri, 28 Feb 2025 00:00:38 +0000</pubDate>
				<category><![CDATA[64-bit]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Rust]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[poker]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3317</guid>

					<description><![CDATA[<p>And it is a fair comparison because the Linux I&#8217;m running (Ubuntu 24.04 LTS) runs on my Windows 11 box in a hyper-V VM. I wrote a Poker hand evaluation program which loaded a text file containing lines of seven playing cards in text format TS 2C 4D sort of thing. It was seven cards [&#8230;]</p>
The post <a href="https://learncgames.com/bit-of-a-curiosity-rust-runs-slower-on-windows-than-linux/">Bit of a curiosity – Rust runs slower on Windows than Linux</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>And it is a fair comparison because the Linux I&#8217;m running (Ubuntu 24.04 LTS) runs on my Windows 11 box in a hyper-V VM. I wrote a Poker hand evaluation program which loaded a text file containing lines of seven playing cards in text format TS 2C 4D sort of thing. It was seven cards because there&#8217;s two in your hand and five on the table.</p>
<p>There were 1,000 lines of these and the program loaded the file into memory, holding the cards in a Vec&lt;Vec&lt;Card&gt;&gt;. Then it loops through the 1,000 elements and figures out the best hand for each set.  The bit that was timed was the loop not the loading the file into memory.</p>
<p>The source file is on GitHub. It has the project files plus some test cards. You can try it yourself. <strong>Note at the bottom of this article is a link to a much faster version.</strong></p>
<pre>https://github.com/David-H-Bolton/Projects/blob/main/rust_pokerhand.zip</pre>
<p>On my PC, the Windows one average time per hand is 768 ns. On Ubuntu is 540ns. Mad eh! The same program runs in 70% of the time on Linux compared to Windows. Both are run with this command from a terminal/command line.</p>
<pre>cargo run --release 1000_card_hads.txt</pre>
<p>You can also try the test_card_hands.txt but you need to enable the show_cards feature. That shows the cards but doesn&#8217;t do timing. The default is do the timing but don&#8217;t show the cards or the evaluation.</p>
<pre>cargo run --release --features show_card test_card_hands.txt</pre>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3319" src="https://learncgames.com/wp-content/uploads/2025/02/testcards.png" alt="Shows the Rust program with the feature" width="750" height="431" srcset="https://learncgames.com/wp-content/uploads/2025/02/testcards.png 750w, https://learncgames.com/wp-content/uploads/2025/02/testcards-300x172.png 300w" sizes="auto, (max-width: 750px) 100vw, 750px" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The test cards say what each hand is and the output at the bottom is the program working out each hand.<br />
The file</p>
<pre>https://github.com/David-H-Bolton/Projects/blob/main/rust_pokerhand_faster.zip</pre>
<p>contains a much faster version. On Linux it takes about 127 ns per hand. On Windows it&#8217;s about 190 ns.</p>The post <a href="https://learncgames.com/bit-of-a-curiosity-rust-runs-slower-on-windows-than-linux/">Bit of a curiosity – Rust runs slower on Windows than Linux</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3317</post-id>	</item>
		<item>
		<title>So I found the fix</title>
		<link>https://learncgames.com/so-i-found-the-fix/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=so-i-found-the-fix</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 23 Feb 2025 20:03:51 +0000</pubDate>
				<category><![CDATA[bugs]]></category>
		<category><![CDATA[Rust]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[Tips]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3312</guid>

					<description><![CDATA[<p>Well actually I asked Microsoft&#8217;s CoPilot AI and it sorted it! This is what you need in the dependencies section in cargo.toml [dependencies] sdl2-sys = &#34;*&#34; sdl2 = { version = &#34;0.37&#34;, features = [&#34;image&#34;,&#34;ttf&#34;] } It compiled with no problems after saving that.</p>
The post <a href="https://learncgames.com/so-i-found-the-fix/">So I found the fix</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3314" src="https://learncgames.com/wp-content/uploads/2025/02/its-fixed.png" alt="It's fixed text on a technology background" width="752" height="436" srcset="https://learncgames.com/wp-content/uploads/2025/02/its-fixed.png 752w, https://learncgames.com/wp-content/uploads/2025/02/its-fixed-300x174.png 300w" sizes="auto, (max-width: 752px) 100vw, 752px" />Well actually I asked Microsoft&#8217;s CoPilot AI and it sorted it!</p>
<p>This is what you need in the dependencies section in cargo.toml</p>
<pre><code class="language-yaml" data-line="">[dependencies]
sdl2-sys = &quot;*&quot;
sdl2 = { version = &quot;0.37&quot;, features = [&quot;image&quot;,&quot;ttf&quot;] }</code></pre>
<p>It compiled with no problems after saving that.</p>The post <a href="https://learncgames.com/so-i-found-the-fix/">So I found the fix</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3312</post-id>	</item>
		<item>
		<title>A slight problem with SDL2 and Rust</title>
		<link>https://learncgames.com/a-slight-problem-with-sdl2-and-rust/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-slight-problem-with-sdl2-and-rust</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 22 Feb 2025 00:05:18 +0000</pubDate>
				<category><![CDATA[bugs]]></category>
		<category><![CDATA[Rust]]></category>
		<category><![CDATA[SDL]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3308</guid>

					<description><![CDATA[<p>This is on Ubuntu 24.04 LTS. I&#8217;ve installed the dev versions of SDL2, including images and TTF.  You can read how to install them in this tutorial. Once that&#8217;s done you add them to the rust project with commands like this cargo add sdl2 You can see these instruction in the relevant crates pages. For [&#8230;]</p>
The post <a href="https://learncgames.com/a-slight-problem-with-sdl2-and-rust/">A slight problem with SDL2 and Rust</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:22,&quot;href&quot;:&quot;https:\/\/crates.io\/crates\/sdl2&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20251226013606\/https:\/\/crates.io\/crates\/sdl2&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:46:48&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-09 20:08:03&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-12 22:35:49&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-18 23:31:02&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-22 05:49:46&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-26 17:30:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-03 01:04:19&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-09 09:34:25&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-12 21:08:00&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-16 05:48:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-19 09:46:55&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-22 20:58:11&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-30 12:24:14&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-03 05:13:08&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-08 07:07:54&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-12 23:19:51&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-16 05:22:10&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-19 08:52:04&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 08:52:04&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:23,&quot;href&quot;:&quot;https:\/\/crates.io\/crates\/sdl2_image&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20241114201358\/https:\/\/crates.io\/crates\/sdl2_image&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:46:50&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-09 20:08:02&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-12 22:35:49&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-18 23:31:02&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-22 05:49:46&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-26 17:30:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-03 01:04:19&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-09 09:34:25&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-12 21:07:59&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-16 05:48:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-19 09:46:55&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-22 20:58:12&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-30 12:24:12&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-03 05:13:09&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-08 07:07:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-13 06:32:44&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-17 05:36:48&quot;,&quot;http_code&quot;:503}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-17 05:36:48&quot;,&quot;http_code&quot;:503},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:24,&quot;href&quot;:&quot;https:\/\/crates.io\/crates\/sdl2_ttf&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20241114201545\/https:\/\/crates.io\/crates\/sdl2_ttf&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:46:51&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-09 20:08:02&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-12 22:35:49&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-18 23:31:02&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-22 05:49:46&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-26 17:30:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-03 01:04:20&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-09 09:34:25&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-12 21:08:00&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-16 05:48:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-19 09:46:55&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-22 20:58:11&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-30 12:24:12&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-03 05:13:09&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-08 07:07:57&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-12 23:19:42&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-16 05:22:11&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-19 08:52:04&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 08:52:04&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3309" src="https://learncgames.com/wp-content/uploads/2025/02/error.png" alt="VS Code Rust SDL Copikle problem" width="996" height="396" srcset="https://learncgames.com/wp-content/uploads/2025/02/error.png 996w, https://learncgames.com/wp-content/uploads/2025/02/error-300x119.png 300w, https://learncgames.com/wp-content/uploads/2025/02/error-768x305.png 768w" sizes="auto, (max-width: 996px) 100vw, 996px" />This is on Ubuntu 24.04 LTS. I&#8217;ve installed the dev versions of SDL2, including images and TTF.  You can read how to install them in <a title="Link to How to install SDL on Linux" href="https://learncgames.com/tutorials/how-to-install-sdl-on-linux/" target="_blank" rel="noopener">this tutoria</a>l.</p>
<p>Once that&#8217;s done you add them to the rust project with commands like this</p>
<pre>cargo add sdl2</pre>
<p>You can see these instruction in the relevant crates pages. For instance <a title="Link to SDL2 Crate" href="https://crates.io/crates/sdl2" target="_blank" rel="noopener">SDL2 crate</a>, <a title="Linbk to SDL2 Image Crate" href="https://crates.io/crates/sdl2_image" target="_blank" rel="noopener">SDL2 Image</a> and <a title="Link to SDL2 TTF crate" href="https://crates.io/crates/sdl2_ttf" target="_blank" rel="noopener">SDL2 TTF</a>.</p>
<p>So far so good. The cargo add added the crates into cargo.toml as expected but when I compiled it. Not a compile error as such but a version of dll hell.</p>
<p>The text in that image says:</p>
<pre><em>Updating crates.io index</em>
<em>error: failed to select a version for `sdl2-sys`.</em>
<em>... required by package `sdl2_image v0.25.0`</em>
<em>... which satisfies dependency `sdl2_image = "^0.25.0"` of package `sdl1 v0.1.0 (/home/david/rust/sdl1)`</em>
<em>versions that meet the requirements `^0.25.0` are: 0.25.0</em>

<em>the package `sdl2-sys` links to the native library `SDL2`, but it conflicts with a previous package which links to `SDL2` as well:</em>
<em>package `sdl2-sys v0.37.0`</em>
<em>... which satisfies dependency `sdl2-sys = "^0.37.0"` of package `sdl1 v0.1.0 (/home/david/rust/sdl1)`</em>
<em>Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "SDL2"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.</em>

<em>failed to select a version for `sdl2-sys` which could resolve this conflict</em></pre>
<p>The problem appears to be a clash between sdl-sys and sdl2-ttf or sdl2-image. If anyone knows a fix&#8230;</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/a-slight-problem-with-sdl2-and-rust/">A slight problem with SDL2 and Rust</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3308</post-id>	</item>
		<item>
		<title>Rust&#8217;s way of importing from other modules is bizarre</title>
		<link>https://learncgames.com/rusts-way-of-importing-from-other-modules-is-bizarre/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rusts-way-of-importing-from-other-modules-is-bizarre</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Mon, 17 Feb 2025 00:05:17 +0000</pubDate>
				<category><![CDATA[Rust]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Struct]]></category>
		<category><![CDATA[unit]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3298</guid>

					<description><![CDATA[<p>I come from a background of Pascal and Delphi. From about 1989 Turbo Pascal 4 and subsequently Delphi had a really useful unit system for breaking a program down into multiple source files. A unit is the equivalent of Rust&#8217;s mod.  Anything you wish to export from a unit is put in the interface section [&#8230;]</p>
The post <a href="https://learncgames.com/rusts-way-of-importing-from-other-modules-is-bizarre/">Rust’s way of importing from other modules is bizarre</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>I come from a background of Pascal and Delphi. From about 1989 Turbo Pascal 4 and subsequently Delphi had a really useful unit system for breaking a program down into multiple source files. A unit is the equivalent of Rust&#8217;s mod.  Anything you wish to export from a unit is put in the interface section of the source file- consts, types, functions etc. Like making them pub in Rust. Then in the source file that wants to use these, you just put <em>using name-of-unit</em>. No hassles, very easy to use and it just works.</p>
<p>Now in Rust, they have a cockermanie system.  I had a main.rs that had several Structs (Card and Game) and decided to put it in another file poker.rs inside a mod poker {.</p>
<p>I made both Structs pub.  When compiling, there&#8217;s no errors in poker.rs but in the main.rs which has</p>
<pre><code class="language-rust" data-line="">pub mod poker;
use poker::{Card, Game};</code></pre>
<p>There&#8217;s red lines under Card and Game.</p>
<p>note:<em> struct `crate::poker::poker::Card` exists but is inaccessible</em> etc. Grrr.</p>
<p><img loading="lazy" decoding="async" class="alignleft wp-image-3299 size-full" src="https://learncgames.com/wp-content/uploads/2025/02/poker.png" alt="Rust compile errors" width="509" height="232" srcset="https://learncgames.com/wp-content/uploads/2025/02/poker.png 509w, https://learncgames.com/wp-content/uploads/2025/02/poker-300x137.png 300w" sizes="auto, (max-width: 509px) 100vw, 509px" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Now, no doubt there is soime way to make this work but why make it so difficult?</p>The post <a href="https://learncgames.com/rusts-way-of-importing-from-other-modules-is-bizarre/">Rust’s way of importing from other modules is bizarre</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3298</post-id>	</item>
		<item>
		<title>Rust &#8211; Sometimes you don&#8217;t need to use HashMap or HashSet</title>
		<link>https://learncgames.com/rust-sometimes-you-dont-need-to-use-hashmap-or-hashset/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rust-sometimes-you-dont-need-to-use-hashmap-or-hashset</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Fri, 14 Feb 2025 00:05:27 +0000</pubDate>
				<category><![CDATA[Rust]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[poker]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3291</guid>

					<description><![CDATA[<p>I wrote a Poker Hand evaluator. It read in a file of a 1,000 randomly generated sets of seven cards like this AC 8H JC &#8230;and figured out what was the best hand. It&#8217;s in Rust and on GitHub. That takes you to a projects folder and the whole rust project complete with two test [&#8230;]</p>
The post <a href="https://learncgames.com/rust-sometimes-you-dont-need-to-use-hashmap-or-hashset/">Rust – Sometimes you don’t need to use HashMap or HashSet</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:25,&quot;href&quot;:&quot;https:\/\/github.com\/David-H-Bolton\/Projects&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20240525100439\/https:\/\/github.com\/David-H-Bolton\/Projects&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:46:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 13:47:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 03:25:33&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-24 16:07:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 22:29:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 00:00:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-17 04:15:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 23:34:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 08:54:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-04 13:02:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 11:19:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-13 04:05:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-17 06:35:58&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-17 06:35:58&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft wp-image-3292" src="https://learncgames.com/wp-content/uploads/2025/02/cards-300x66.png" alt="Seven playing cards" width="498" height="110" srcset="https://learncgames.com/wp-content/uploads/2025/02/cards-300x66.png 300w, https://learncgames.com/wp-content/uploads/2025/02/cards-768x170.png 768w, https://learncgames.com/wp-content/uploads/2025/02/cards.png 770w" sizes="auto, (max-width: 498px) 100vw, 498px" />I wrote a Poker Hand evaluator. It read in a file of a 1,000 randomly generated sets of seven cards like this AC 8H JC &#8230;and figured out what was the best hand. It&#8217;s in Rust and on <a href="https://github.com/David-H-Bolton/Projects">GitHub.</a> That takes you to a projects folder and the whole rust project complete with two test sets of cards are included. Look for the file Rust_pokerhand.zip.</p>
<p>Now in the Hand evaluation I used both a HashMap and HashSet.  Here for example is the code to count how many of each Rank there are.</p>
<pre><code class="language-rust" data-line="">    let mut rank_counts = HashMap::new();
    for card in cards.iter() {
        *rank_counts.entry(card.rank).or_insert(0) += 1;
    }
</code></pre>
<p>The program reads in the cards into a Vec&lt;Vec&lt;Card&gt;&gt; and then calculate the average time to evaluate a hand.</p>
<p>Now there&#8217;s nothing wrong with the program. One of the card sets is called test_card_hands.txt and has an instance of each hand type along with a comment.</p>
<pre>5H AS 2D 6C 3S KD 7C - High card
7H 3D 8S 7C 4H 9H JC - One Pair
AD 7H 8C AC 5S 8D KS - Two Pairs

</pre>
<p>You can run that with this command:</p>
<pre>cargo run --release --features "show_cards" test_card_hands.txt</pre>
<p>Or if you run the other test set with this, it doesn&#8217;t show the cards but does calculate the average time.</p>
<pre>cargo run --release 1000_card_hands.txt</pre>
<p>If I run this on Windows it evaluates a hand in 780 ns on average and on Ubuntu 24.04 on the same PC, (running under Hyper-V), it&#8217;s faster typically 550 ns.</p>
<p>So, I was looking for ways to speed it up and thought.  The HasmMap and HashSets are running on small numbers of Cards. 13 for Ranks and 4 for suits so what if I use them as arrays. Would it be faster?</p>
<p>It was, roughly <strong>four times faster</strong>.</p>
<p>As an example, the code above I replaced with this:</p>
<div>
<div>
<pre><code class="language-rust" data-line="">    let mut rank_counts = [0,0,0,0,0,0,0,0,0,0,0,0,0];
    for card in cards.iter() {
       rank_counts[&amp;card.rank.value()-2] += 1;
    }</code></pre>
</div>
</div>
<p>That needed a value() method that mapped all the Ranks starting at 2, onto 2-14.</p>
<p>I also redid the code for working out a straight.</p>
<p>The original is this, plus a bit more to check for A2345:</p>
<pre><code class="language-rust" data-line="">    let mut values: HashSet&lt;u8&gt; = cards.iter().map(|card| card.rank.value()).collect();
    let mut unique_values: Vec&lt;u8&gt; = values.drain().collect();
    unique_values.sort_unstable();

    let mut straight_length = 1;
    for i in 1..unique_values.len() {
        if unique_values[i] == unique_values[i - 1] + 1 {
            straight_length += 1;
            if straight_length == 5 {
                is_straight = true;
                break;
            }
        } else {
            straight_length = 1;
        }
    }</code></pre>
<pre>The improved version uses this constant

static STRAIGHTS: &amp;'static [i32]=&amp;[7936, 3968, 1984, 992, 496, 248, 124, 62, 31, 7681];</pre>
<p>Plus a binvalue function which maps the card Ranks onto 1,2,4,8 etc. Just or the Cards binValues together and &#8216;ands&#8217; (&amp;) it with the individual STRAIGHTS values.</p>
<pre><code class="language-rust" data-line="">      let mut bivalue=0;
      for card in cards.iter() {
        bivalue |= card.rank.binvalue();
      }   

      for i in 0..STRAIGHTS.len(){
        if &amp;binvalue &amp; STRAIGHTS[i]== STRAIGHTS[i] {
            is_straight= true;
            break;
        }
    }</code></pre>The post <a href="https://learncgames.com/rust-sometimes-you-dont-need-to-use-hashmap-or-hashset/">Rust – Sometimes you don’t need to use HashMap or HashSet</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3291</post-id>	</item>
		<item>
		<title>A new year, new language</title>
		<link>https://learncgames.com/a-new-year-new-language/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-new-year-new-language</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 25 Jan 2025 00:05:22 +0000</pubDate>
				<category><![CDATA[Rust]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3279</guid>

					<description><![CDATA[<p>I&#8217;ve switched to learning Rust hence the corny image. It is an interesting programming language where the Rust compiler can stop you introducing bugs at compile time. It&#8217;s very strong on ownership of variables.  However my interest lies in the area of games and to that end you can get  bindings for libraries like SDL [&#8230;]</p>
The post <a href="https://learncgames.com/a-new-year-new-language/">A new year, new language</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:28,&quot;href&quot;:&quot;https:\/\/www.rust-lang.org&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205173828\/https:\/\/rust-lang.org\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 11:03:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 08:22:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-17 04:49:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-23 00:52:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 15:18:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 18:29:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-07 18:00:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 08:12:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-16 11:42:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-03 10:20:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-06 21:01:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-10 12:15:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-15 21:21:30&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-15 21:21:30&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft wp-image-3281 size-medium" src="https://learncgames.com/wp-content/uploads/2025/01/A-rusty-computer-with-a-lot-more-rust-texture-300x300.jpg" alt="Rusty computer by Copilot" width="300" height="300" srcset="https://learncgames.com/wp-content/uploads/2025/01/A-rusty-computer-with-a-lot-more-rust-texture-300x300.jpg 300w, https://learncgames.com/wp-content/uploads/2025/01/A-rusty-computer-with-a-lot-more-rust-texture-150x150.jpg 150w, https://learncgames.com/wp-content/uploads/2025/01/A-rusty-computer-with-a-lot-more-rust-texture-768x768.jpg 768w, https://learncgames.com/wp-content/uploads/2025/01/A-rusty-computer-with-a-lot-more-rust-texture-250x250.jpg 250w, https://learncgames.com/wp-content/uploads/2025/01/A-rusty-computer-with-a-lot-more-rust-texture.jpg 1024w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>I&#8217;ve switched to learning <a title="Link to official Rust website" href="https://www.rust-lang.org/" target="_blank" rel="noopener">Rust</a> hence the corny image.</p>
<p>It is an interesting programming language where the Rust compiler can stop you introducing bugs at compile time. It&#8217;s very strong on ownership of variables.  However my interest lies in the area of games and to that end you can</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>get  bindings for libraries like SDL</li>
<li>generate WASM for browser games.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>It&#8217;s cross-platform and you can setup VS Code with a couple of extensions on Windows and Linux (Mac as well but I haven&#8217;t got oneto test that) though I noticed a curious thing.  The same program, built and run on Ubuntu in a Hyper-V is quicker than running on Windows. Both were optiomized builds &#8211; the Hyper-V Ubuntu took 266 ns, the Windows 388 ns.</p>The post <a href="https://learncgames.com/a-new-year-new-language/">A new year, new language</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3279</post-id>	</item>
	</channel>
</rss>
