技術記事 – 株式会社TerraceTech(テラステック) https://terracetech.jp ~人と技術で未来をテラス~ Sun, 18 Jul 2021 00:27:20 +0000 ja hourly 1 https://terracetech.jp/wp-content/uploads/2019/11/cropped-1657-1-32x32.png 技術記事 – 株式会社TerraceTech(テラステック) https://terracetech.jp 32 32 [Rust] typeof のようにその値の型が知りたいとき https://terracetech.jp/2021/07/19/rust-typeof/ Mon, 19 Jul 2021 00:24:01 +0000 https://terracetech.jp/?p=884 [Rust] typeof のようにその値の型が知りたいとき

 

fn main() {
let mut my_number = 32.90;
my_number.what_is_this();
}

 

持っていないメソッドを実行する

   Compiling playground v0.0.1 (/playground)
error[E0599]: no method named `what_is_this` found for type `{float}` in the current scope
 --> src/main.rs:3:11
  |
3 | my_number.what_is_this();
  |           ^^^^^^^^^^^^ method not found in `{float}`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground`

To learn more, run the command again with --verbose.

怒られてfloatの中にそのようなメソッドはないと言われる
floatだとわかる

]]>
[Rust]解決。use of deprecated associated function `actix_web::App::::data`: Use `.app_data(Data::new(val))` instead. https://terracetech.jp/2021/07/18/rust/ Sun, 18 Jul 2021 01:41:27 +0000 https://terracetech.jp/?p=879 use of deprecated associated function `actix_web::App::<T, B>::data`: Use `.app_data(Data::new(val))` instead.
HttpServer::new(move || App::new().service(index).data(pool.clone()

背景

実戦Rustプログラミング入門をやっていると

ビルド時に

use of deprecated associated function `actix_web::App::<T, B>::data`: Use `.app_data(Data::new(val))` instead.

 

に言われることがあります。

解決策

「use of deprecated associated function」

そちらはもう廃止な書き方になったので

そこにあるように

app_dataを使いましょうと言うことのようです

.data

になっているところを

to

HttpServer::new(move || App::new().service(index).app_data(pool.clone())).bind(“0.0.0.0:8080”)?
.run().await?;
Ok(())

 

こちらでそのwaringは消えますが、実施にlocalhostにアクセスすると.dataを使えと言われます。
なので
そのwarningは無視してcargo run。
結果dataを使って表示をさせました

]]>
[Rust]解決。failed to select a version for `libsqlite3-sys` which could resolve this conflict https://terracetech.jp/2021/07/17/rust-failed-to-select-a-version-for-libsqlite3-sys-which-could-resolve-this-conflict/ Sat, 17 Jul 2021 01:22:27 +0000 https://terracetech.jp/?p=871 [Rust]解決。failed to select a version for `libsqlite3-sys` which could resolve this conflict

実戦Rustプログラミング入門をやっていると、

バージョンが合わずビルド時にこけます。書籍は情報が古くなるので最新の情報を見ましょう

 

Cargo.tomを

[dependencies]
actix-rt = “2.2.0”
actix-web = “4.0.0-beta.3”
askama = “0.10.5”
thiserror = “1.0.26”
rusqlite = {version = “0.23”, feature=[“bundled”]}
r2d2 = “0.8.9”
r2d2_sqlite = “0.18.0”

だったのを

 

https://github.com/rusqlite/rusqlite#notes-on-building-rusqlite-and-libsqlite3-sys

を見て

[dependencies]
actix-rt = “2.2.0”
actix-web = “4.0.0-beta.3”
askama = “0.10.5”
thiserror = “1.0.26”
rusqlite = {version = “0.25.1”, feature=[“bundled”]}
r2d2 = “0.8.9”
r2d2_sqlite = “0.18.0”

 

にしました

このようにすれば現時点ではいけました。最新の情報を参照してください

]]>
[Rust] Rust製プロジェクトにgitignoreを追加 https://terracetech.jp/2021/07/11/rust-gitignore/ Sun, 11 Jul 2021 09:27:55 +0000 https://terracetech.jp/?p=868 [Rust] rust製プロジェクトにgitignoreを追加

https://raw.githubusercontent.com/github/gitignore/master/Rust.gitignore

“`rust
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
“`

]]>
[React] map時にどんな要素が出力されているかを確認したい時、一々{}で囲わないで済む方法 https://terracetech.jp/2021/07/05/react-map-tips/ Mon, 05 Jul 2021 10:48:10 +0000 https://terracetech.jp/?p=864 [React] map時にどんな要素が出力されているかを確認したい時、一々{}で囲わないで済む方法

]]>
voltaの設定方法(nodenvから移行) https://terracetech.jp/2021/06/16/volta-nodenv/ Wed, 16 Jun 2021 13:36:23 +0000 https://terracetech.jp/?p=823 voltaの設定方法(nodenvから移行)

voltaの設定(how to settings)

volta

volta settings

author

スター頂けるとやる気出ます

volta document

pos

– Rust製で速い
– node, npm, yarnと別でプロジェクト毎にver管理できる
– MacM1でも問題ない
– jsonで管理
– チームで共有できる

cons

– 情報が少ない
– uninstallする際に大変らしい
– yarnとdenoのサポートがいまいちらしい

設定ハンズオン

1. install

curl https://get.volta.sh | bash

Creating directory layout
Extracting Volta binaries and launchers
Finished installation. Updating user profile settings.
Updating your Volta directory. This may take a few moments…
success: Setup complete. Open a new terminal to start using Volta!

パスも最初から通してくれている

2. shell再起動

3. node指定

– メジャーバージョンだけ指定する場合

volta install node@14

– LTSを使いたい場合

volta install node

cd ~/Desktop
mkdir test && cd test

以下 test配下で叩く

4. defaultバージョンを決める

volta install node@14

success: installed and set node@14.17.1 (with npm@6.14.13) as default

5. npm init -y

プロジェクトに`package.json`を作って、その中に設定される(`nodenvのnode_versions`のようなものを`package.json`に記述される)

6. volta pin node@12.20

ここで設定

再起動

以下環境に応じて

uninstall nodenv

必要に応じてnodenvをアンインストールする

[https://github.com/nodenv/nodenv#uninstalling-nodenv](https://github.com/nodenv/nodenv#uninstalling-nodenv)

]]>
VSCodeで突然「The window has crashed (reason: ‘killed’)」が出たら https://terracetech.jp/2021/06/12/vscode-the-window-has-crashed-reason-killed/ Sat, 12 Jun 2021 10:01:45 +0000 https://terracetech.jp/?p=814

VSCodeで突然「The window has crashed (reason: ‘killed’)」が出たら

VSCodeで突然「The window has crashed (reason: 'killed')」が出たら

何か感に触れたのかVSCodeが立ち上がらなくなってしまいました
そこのボタンどっち押してもダメです

自分はターミナルを立ち上げて適当なフォルダを
code hogehoge
としてコマンドで立ち上げたら上手く行きました

たまたま
コマンドを入れていたからよかったですけれど
入れてない人はどうしたら良いのでしょうか

もし自分がその立場だったらアプリを再インストールしていたかもしれないです
設定もだるいですね

以上
「VSCodeで突然「The window has crashed (reason: ‘killed’)」が出たら」
でした

]]>