<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Konstantin</title>
    <description>The latest articles on DEV Community by Konstantin (@hbko).</description>
    <link>https://dev.to/hbko</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F112216%2F911aff7f-a8a7-422f-874d-0fedf51b3252.jpeg</url>
      <title>DEV Community: Konstantin</title>
      <link>https://dev.to/hbko</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hbko"/>
    <language>en</language>
    <item>
      <title>How to always Paste and Match Style on macOS</title>
      <dc:creator>Konstantin</dc:creator>
      <pubDate>Tue, 17 May 2022 17:01:06 +0000</pubDate>
      <link>https://dev.to/hbko/how-to-always-paste-and-match-style-on-macos-b2h</link>
      <guid>https://dev.to/hbko/how-to-always-paste-and-match-style-on-macos-b2h</guid>
      <description>&lt;h2&gt;
  
  
  How to always Paste and Match Style on macOS
&lt;/h2&gt;

&lt;p&gt;It’s safe to say that some of us do a lot of copy-pasting during the day. (StackOverflow even &lt;a href="https://www.theverge.com/22761188/stack-overflow-the-key-copy-paste-review-price-release-date-keyboard"&gt;sells a dedicated keyboard&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;While the ability to copy content from one app and paste it into another is probably in the TOP 3 productivity features of a modern computer, it doesn’t come without its quirks…&lt;/p&gt;

&lt;p&gt;Just in case you don’t know what I’m talking about - when you copy some text content from a place with formatting (like custom font, colors, etc.) and then paste it into another app that also supports (to some extent) rich text formatting.&lt;/p&gt;

&lt;p&gt;By default, copy-paste (⌘ + C / ⌘ + V) allows an app to capture all &lt;a href="https://developer.apple.com/documentation/appkit/nspasteboarditem/1508499-types"&gt;available content types&lt;/a&gt; when pasting. As a result, copying a snippet from a web page comes in both plain text and rich/formatted text. All worldly computer things have opted to use the richest form of content available in the clipboard when pasting for reasons beyond my understanding 🙄.&lt;/p&gt;

&lt;p&gt;Honestly, I can’t remember when (if at all) I needed this behavior. In all cases, I want the source text to match the destination formatting as best as possible. This feature exists; it’s the &lt;strong&gt;Edit&lt;/strong&gt; &amp;gt; &lt;strong&gt;Paste and Match Style&lt;/strong&gt; command.&lt;/p&gt;

&lt;p&gt;To fix this in (almost) all apps, you head to System Preferences &amp;gt; Keyboard &amp;gt; Shortcuts &amp;gt; App Shortcuts and then hit the plus button to create a new shortcut with the menu title “Paste and Match Style” and assigning ⌘ + V! That’s it 🎉! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsenpst8m4wurz1aqifps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsenpst8m4wurz1aqifps.png" alt="Screenshot of the macOS system preferences showing custom app shortcuts." width="800" height="726"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;⚠️ This technique does not work in Microsoft apps like Word, which chooses to override and shamelessly disregard the user’s system preferences or (most of) the text services provided by macOS 🤷🏻‍♂️.&lt;/p&gt;

</description>
      <category>macos</category>
      <category>productivity</category>
      <category>stackoverflow</category>
      <category>shortcuts</category>
    </item>
    <item>
      <title>Adding an executable target to a Rust library</title>
      <dc:creator>Konstantin</dc:creator>
      <pubDate>Mon, 16 May 2022 05:12:36 +0000</pubDate>
      <link>https://dev.to/hbko/adding-an-executable-target-to-a-rust-library-3hej</link>
      <guid>https://dev.to/hbko/adding-an-executable-target-to-a-rust-library-3hej</guid>
      <description>&lt;p&gt;Using Cargo, we can easily create a library project with the &lt;code&gt;new&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo new pumpkin-rs &lt;span class="nt"&gt;--lib&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, the primary purpose of libraries is to encapsulate some kind of functionality that can be then exported for use by other libraries or applications.&lt;/p&gt;

&lt;p&gt;For the purpose of this post, let’s define a simple function in &lt;code&gt;src/lib.rs&lt;/code&gt; which will be the essence of our library. Later we will see how we can use this function from a runnable binary target in the same project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;say_hello&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello from the library"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may run &lt;code&gt;cargo build&lt;/code&gt; just to double-check everything builds successfully… and voilà!&lt;/p&gt;

&lt;h2&gt;
  
  
  Cargo Targets
&lt;/h2&gt;

&lt;p&gt;In certain situations, it may be helpful to have a library project include a runnable component - a stand-alone, runnable program that can be executed.&lt;/p&gt;

&lt;p&gt;Cargo &lt;a href="https://doc.rust-lang.org/cargo/reference/cargo-targets.html"&gt;targets&lt;/a&gt; allow us to define different combinations of source files which can be compiled in a project. Targets can specify what part of the source code is a library, binary, example, unit test, or benchmark.&lt;/p&gt;

&lt;p&gt;The cool thing is that Cargo also uses folder structure &lt;a href="https://doc.rust-lang.org/cargo/guide/project-layout.html"&gt;conventions&lt;/a&gt; to guess which source file does what. For example, &lt;code&gt;src/lib.rs&lt;/code&gt; is where it will look for the library code, executable code is expected in &lt;code&gt;src/main.rs&lt;/code&gt; or &lt;code&gt;src/bin/&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add a default binary target
&lt;/h3&gt;

&lt;p&gt;Following the conventions above, we can add a default executable to a library project by creating &lt;code&gt;src/bin/pumpkin.rs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;pumpkin_rs&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;say_hello&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;say_hello&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running &lt;code&gt;cargo run&lt;/code&gt; will execute the binary! 🎉&lt;/p&gt;

&lt;p&gt;Not only that, but &lt;code&gt;cargo build&lt;/code&gt; now also produces 2 separate outputs - we get the compiled binary for the library as well as the executable.&lt;/p&gt;

&lt;h3&gt;
  
  
  More than one binary targets
&lt;/h3&gt;

&lt;p&gt;We are not limited to a single binary target. There can be more than one!&lt;br&gt;
Let’s create &lt;code&gt;src/bin/tomato.rs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello 🍅"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if we just run &lt;code&gt;cargo run&lt;/code&gt; like before, we’d get an error message because there are two available binary targets, and cargo doesn’t know which one we want to use. The error message helpfully suggests we can use the target configuration in &lt;code&gt;Cargo.toml&lt;/code&gt; to define a &lt;code&gt;default-run&lt;/code&gt; key or pass the &lt;code&gt;--bin&lt;/code&gt; argument to the &lt;code&gt;run&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;cargo&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt; &lt;span class="n"&gt;tomato&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>rust</category>
      <category>library</category>
      <category>targets</category>
      <category>snippets</category>
    </item>
  </channel>
</rss>
