差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
rust:language_memo [2024/06/14 13:38] – [慣れていないと戸惑うもの...😲] ともやんrust:language_memo [2024/06/17 07:09] (現在) – [もしもハマってしまったら...🔰] ともやん
行 376: 行 376:
 <font color="#444444">  23</font> <font color="#F8F8F2">#[allow(unused_imports)]</font> <font color="#444444">  23</font> <font color="#F8F8F2">#[allow(unused_imports)]</font>
 <font color="#444444">  24</font> <font color="#F92672">use</font><font color="#F8F8F2"> spinners::{Spinner, Spinners};</font> <font color="#444444">  24</font> <font color="#F92672">use</font><font color="#F8F8F2"> spinners::{Spinner, Spinners};</font>
 +</pre></html></WRAP>
 +</WRAP>
 +
 +=== モジュール、クレート全体に属性を付与 ===
 +[[https://doc.rust-lang.org/reference/attributes.html|Attributes - The Rust Reference]]\\
 +[[so>questions/27454761/what-is-a-crate-attribute-and-where-do-i-add-it|rust - What is a crate attribute and where do I add it? - Stack Overflow]]\\
 +
 +ファイルの先頭で <html><code>#!</code></html> 構文で <html><code>#![allow(unused)]</code></html>を使う🤔\\
 +diesel_ext で model を生成すると書かれている😉\\
 +<WRAP color_term>
 +<WRAP color_result><html><pre>
 +<font color="#75715E">// Generated by diesel_ext</font>
 +
 +<font color="#F8F8F2">#![allow(unused)]</font>
 </pre></html></WRAP> </pre></html></WRAP>
 </WRAP> </WRAP>
行 387: 行 401:
 ==== Try - Catch ステートメント ==== ==== Try - Catch ステートメント ====
 [[so>questions/55755552/what-is-the-rust-equivalent-to-a-try-catch-statement|error handling - What Is the Rust Equivalent to a Try-Catch Statement? - Stack Overflow]]\\ [[so>questions/55755552/what-is-the-rust-equivalent-to-a-try-catch-statement|error handling - What Is the Rust Equivalent to a Try-Catch Statement? - Stack Overflow]]\\
 +
 +===== もしもハマってしまったら...🤪🔰 =====
 +
 +==== cargo add tokio してるのに #[tokio::main] が使えない 😅 ====
 +[[so>questions/63874178/cannot-find-tokiomain-macro|rust - Cannot find tokio::main macro? - Stack Overflow]]\\
 +<WRAP color_term>
 +<WRAP color_result><html><pre>
 +<font color="#F66151"><b>error[E0433]</b></font><b>: failed to resolve: could not find `main` in `tokio`</b>
 +  <font color="#2A7BDE"><b>--&gt; </b></font>src/main.rs:69:10
 +   <font color="#2A7BDE"><b>|</b></font>
 +<font color="#2A7BDE"><b>69</b></font> <font color="#2A7BDE"><b>|</b></font> #[tokio::main]
 +   <font color="#2A7BDE"><b>| </b></font>         <font color="#F66151"><b>^^^^</b></font> <font color="#F66151"><b>could not find `main` in `tokio`</b></font>
 +</pre></html></WRAP>
 +</WRAP>
 +
 +[[https://docs.rs/tokio/latest/tokio/attr.main.html|main in tokio - Rust]]\\
 +<html><code>#[main]</code></html> には Cargo.toml の <html><code>features = ["rt", "macros"]</code></html> が必要です🤔\\
 +Available on crate features <wrap em>rt</wrap> and <wrap em>macros</wrap> only.\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<font color="#0087FF"><b>$</b></font> <font color="#26A269">bat</font><font color="#FF9999"> </font><font color="#A347BA">-p</font><font color="#FF9999"> </font><font color="#A347BA">--pager=never</font><font color="#FF9999"> </font><font color="#FF9999"><u style="text-decoration-style:solid">Cargo.toml</u></font>
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +<font color="#F92672">tokio</font><font color="#F8F8F2"> = { </font><font color="#F92672">version</font><font color="#F8F8F2"> = </font><font color="#E6DB74">&quot;1.38.0&quot;</font><font color="#F8F8F2">, </font><font color="#F92672">features</font><font color="#F8F8F2"> = [</font><font color="#E6DB74">&quot;rt&quot;</font><font color="#F8F8F2">, </font><font color="#E6DB74">&quot;macros&quot;</font><font color="#F8F8F2">] }</font>
 +</pre></html></WRAP>
 +</WRAP>
 +
 +<html><code>#[tokio::main]</code></html> には Cargo.toml の <html><code>features = ["rt-multi-thread", "macros"]</code></html> が必要です🤔\\
 +Note: The multi-threaded runtime requires the <wrap em>rt-multi-thread</wrap> feature flag.\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<font color="#0087FF"><b>$</b></font> <font color="#26A269">bat</font><font color="#FF9999"> </font><font color="#A347BA">-p</font><font color="#FF9999"> </font><font color="#A347BA">--pager=never</font><font color="#FF9999"> </font><font color="#FF9999"><u style="text-decoration-style:solid">Cargo.toml</u></font>
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +<font color="#F92672">tokio</font><font color="#F8F8F2"> = { </font><font color="#F92672">version</font><font color="#F8F8F2"> = </font><font color="#E6DB74">&quot;1.38.0&quot;</font><font color="#F8F8F2">, </font><font color="#F92672">features</font><font color="#F8F8F2"> = [</font><font color="#E6DB74">&quot;rt-multi-thread&quot;</font><font color="#F8F8F2">, </font><font color="#E6DB74">&quot;macros&quot;</font><font color="#F8F8F2">] }</font>
 +</pre></html></WRAP>
 +</WRAP>
  
 ===== FFI - Foreign Function Interface ===== ===== FFI - Foreign Function Interface =====
  • rust/language_memo.1718339929.txt.gz
  • 最終更新: 2024/06/14 13:38
  • by ともやん