{"id":11592,"date":"2025-08-17T16:15:16","date_gmt":"2025-08-17T16:15:16","guid":{"rendered":"https:\/\/putridparrot.com\/blog\/?p=11592"},"modified":"2025-08-17T16:15:16","modified_gmt":"2025-08-17T16:15:16","slug":"rust-postfix","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/rust-postfix\/","title":{"rendered":"Rust, postfix &#8220;?&#8221;"},"content":{"rendered":"<p>Let&#8217;s assume we have a function such as and we have the line highlight ending in a &#8220;?&#8221; &#8211; what&#8217;s this doing?<\/p>\n<pre class=\"brush: cpp; highlight: [2]; title: ; notranslate\" title=\"\">\r\nfn get_history() -&gt; Result&lt;Vec&lt;Revision&gt;, String&gt; {\r\n   let revisions: Vec&lt;Revision&gt; = get_revisions()?;\r\n   return Ok(revisions)\r\n}\r\n<\/pre>\n<p>We can see that the return is a Result &#8211; which is an enum that essentially looks like this<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nenum Result&lt;T, E&gt; {\r\n    Ok(T),\r\n    Err(E),\r\n}\r\n<\/pre>\n<p>Hence our <em>get_history<\/em> function can return a Vec&lt;Revision&gt; which might me Ok (for success ofcourse) or an Err (for an error). <\/p>\n<p>Okay, so what&#8217;s the highlighted code doing, especially as we only appear to return an Ok?<\/p>\n<p>This is essentially is the same as the following<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nlet revisions = match get_revisions() {\r\n  Ok(val) =&gt; val,\r\n  Err(e) =&gt; return Err(e)\r\n};\r\n<\/pre>\n<p>As we can see this is a nice bit of semantic sugar to return an error from the function OR assign the Ok result to the <em>revisions<\/em> variable.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s assume we have a function such as and we have the line highlight ending in a &#8220;?&#8221; &#8211; what&#8217;s this doing? fn get_history() -&gt; Result&lt;Vec&lt;Revision&gt;, String&gt; { let revisions: Vec&lt;Revision&gt; = get_revisions()?; return Ok(revisions) } We can see that the return is a Result &#8211; which is an enum that essentially looks like this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[191],"tags":[],"class_list":["post-11592","post","type-post","status-publish","format-standard","hentry","category-rust"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=11592"}],"version-history":[{"count":4,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11592\/revisions"}],"predecessor-version":[{"id":11634,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11592\/revisions\/11634"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=11592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=11592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=11592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}