概要
wslでrustやってみた。
rusliteクレートを呼びつけて、使ってみた。
参考にしたページ
操作手順
~$ ls
anti-aging.db dets_simple_storage nerves test.db
bootgrub elixir slides.pdf test.txt
bootgrub.gz:Zone.Identifier git slides.pdf:Zone.Identifier test2.pdf
db.json github test test2.pdf:Zone.Identifier
~$ sudo apt install rust-all
[sudo] password for ore:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
cargo gdb gdbserver libbabeltrace1 libc-dev-bin libc6 libc6-dbg libc6-dev libdw1 libelf1 libssh2-1 libstd-rust-1.75
libstd-rust-dev rust-clippy rust-gdb rustc rustfmt
Suggested packages:
cargo-doc gdb-doc glibc-doc rust-doc rust-src llvm-17 lld-17 clang-17
The following NEW packages will be installed:
cargo gdb gdbserver libbabeltrace1 libc6-dbg libdw1 libssh2-1 libstd-rust-1.75 libstd-rust-dev rust-all rust-clippy
rust-gdb rustc rustfmt
The following packages will be upgraded:
libc-dev-bin libc6 libc6-dev libelf1
4 upgraded, 14 newly installed, 0 to remove and 215 not upgraded.
Need to get 123 MB of archives.
After this operation, 453 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libc6-dev amd64 2.31-0ubuntu9.16 [2520 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libc-dev-bin amd64 2.31-0ubuntu9.16 [71.6 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libc6 amd64 2.31-0ubuntu9.16 [2723 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libelf1 amd64 0.176-1.1ubuntu0.1 [44.2 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libdw1 amd64 0.176-1.1ubuntu0.1 [226 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/main amd64 libbabeltrace1 amd64 1.5.8-1build1 [156 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 gdb amd64 9.2-0ubuntu1~20.04.2 [3221 kB]
Get:8 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 gdbserver amd64 9.2-0ubuntu1~20.04.2 [222 kB]
Get:9 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 libssh2-1 amd64 1.8.0-2.1ubuntu0.1 [75.5 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 libstd-rust-1.75 amd64 1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04 [42.5 MB]
Get:11 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 libstd-rust-dev amd64 1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04 [36.8 MB]
Get:12 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 rustc amd64 1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04 [3175 kB]
Get:13 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 rustfmt amd64 1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04 [2004 kB]
Get:14 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 rust-clippy amd64 1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04 [2447 kB]
Get:15 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 rust-gdb all 1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04 [238 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 cargo amd64 1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04 [6110 kB]
Get:17 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 rust-all all 1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04 [232 kB]
Get:18 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libc6-dbg amd64 2.31-0ubuntu9.16 [20.0 MB]
Fetched 123 MB in 19s (6336 kB/s)
Preconfiguring packages ...
(Reading database ... 72650 files and directories currently installed.)
Preparing to unpack .../libc6-dev_2.31-0ubuntu9.16_amd64.deb ...
Unpacking libc6-dev:amd64 (2.31-0ubuntu9.16) over (2.31-0ubuntu9.12) ...
Preparing to unpack .../libc-dev-bin_2.31-0ubuntu9.16_amd64.deb ...
Unpacking libc-dev-bin (2.31-0ubuntu9.16) over (2.31-0ubuntu9.12) ...
Preparing to unpack .../libc6_2.31-0ubuntu9.16_amd64.deb ...
Unpacking libc6:amd64 (2.31-0ubuntu9.16) over (2.31-0ubuntu9.12) ...
Setting up libc6:amd64 (2.31-0ubuntu9.16) ...
(Reading database ... 72650 files and directories currently installed.)
Preparing to unpack .../00-libelf1_0.176-1.1ubuntu0.1_amd64.deb ...
Unpacking libelf1:amd64 (0.176-1.1ubuntu0.1) over (0.176-1.1build1) ...
Selecting previously unselected package libdw1:amd64.
Preparing to unpack .../01-libdw1_0.176-1.1ubuntu0.1_amd64.deb ...
Unpacking libdw1:amd64 (0.176-1.1ubuntu0.1) ...
Selecting previously unselected package libbabeltrace1:amd64.
Preparing to unpack .../02-libbabeltrace1_1.5.8-1build1_amd64.deb ...
Unpacking libbabeltrace1:amd64 (1.5.8-1build1) ...
Selecting previously unselected package gdb.
Preparing to unpack .../03-gdb_9.2-0ubuntu1~20.04.2_amd64.deb ...
Unpacking gdb (9.2-0ubuntu1~20.04.2) ...
Selecting previously unselected package gdbserver.
Preparing to unpack .../04-gdbserver_9.2-0ubuntu1~20.04.2_amd64.deb ...
Unpacking gdbserver (9.2-0ubuntu1~20.04.2) ...
Selecting previously unselected package libssh2-1:amd64.
Preparing to unpack .../05-libssh2-1_1.8.0-2.1ubuntu0.1_amd64.deb ...
Unpacking libssh2-1:amd64 (1.8.0-2.1ubuntu0.1) ...
Selecting previously unselected package libstd-rust-1.75:amd64.
Preparing to unpack .../06-libstd-rust-1.75_1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04_amd64.deb ...
Unpacking libstd-rust-1.75:amd64 (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Selecting previously unselected package libstd-rust-dev:amd64.
Preparing to unpack .../07-libstd-rust-dev_1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04_amd64.deb ...
Unpacking libstd-rust-dev:amd64 (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Selecting previously unselected package rustc.
Preparing to unpack .../08-rustc_1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04_amd64.deb ...
Unpacking rustc (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Selecting previously unselected package rustfmt.
Preparing to unpack .../09-rustfmt_1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04_amd64.deb ...
Unpacking rustfmt (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Selecting previously unselected package rust-clippy.
Preparing to unpack .../10-rust-clippy_1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04_amd64.deb ...
Unpacking rust-clippy (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Selecting previously unselected package rust-gdb.
Preparing to unpack .../11-rust-gdb_1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04_all.deb ...
Unpacking rust-gdb (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Selecting previously unselected package cargo.
Preparing to unpack .../12-cargo_1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04_amd64.deb ...
Unpacking cargo (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Selecting previously unselected package rust-all.
Preparing to unpack .../13-rust-all_1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04_all.deb ...
Unpacking rust-all (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Selecting previously unselected package libc6-dbg:amd64.
Preparing to unpack .../14-libc6-dbg_2.31-0ubuntu9.16_amd64.deb ...
Unpacking libc6-dbg:amd64 (2.31-0ubuntu9.16) ...
Setting up libstd-rust-1.75:amd64 (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Setting up libc6-dbg:amd64 (2.31-0ubuntu9.16) ...
Setting up libstd-rust-dev:amd64 (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Setting up gdbserver (9.2-0ubuntu1~20.04.2) ...
Setting up libssh2-1:amd64 (1.8.0-2.1ubuntu0.1) ...
Setting up rust-clippy (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Setting up rustfmt (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Setting up libc-dev-bin (2.31-0ubuntu9.16) ...
Setting up libelf1:amd64 (0.176-1.1ubuntu0.1) ...
Setting up libdw1:amd64 (0.176-1.1ubuntu0.1) ...
Setting up libbabeltrace1:amd64 (1.5.8-1build1) ...
Setting up libc6-dev:amd64 (2.31-0ubuntu9.16) ...
Setting up gdb (9.2-0ubuntu1~20.04.2) ...
Setting up rustc (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Setting up rust-gdb (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Setting up cargo (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Setting up rust-all (1.75.0+dfsg0ubuntu1~bpo0-0ubuntu0.20.04) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
~$ rustc --version
rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball)
~$ cargo --version
cargo 1.75.0
~$ mkdir rust
~$ cd rust
~/rust$ cargo new sql
Created binary (application) `sql` package
~/rust$ cd sql
~/rust/sql$ cargo add rusqlite
Updating crates.io index
Adding rusqlite v0.32.1 to dependencies.
Features:
41 deactivated features
Updating crates.io index
~/rust/sql$ explorer.exe .
~/rust/sql$ cargo build
Downloaded ahash v0.8.11
Downloaded pkg-config v0.3.31
Downloaded fallible-iterator v0.3.0
Downloaded cfg-if v1.0.0
Downloaded version_check v0.9.5
Downloaded fallible-streaming-iterator v0.1.9
Downloaded hashlink v0.9.1
Downloaded smallvec v1.13.2
Downloaded bitflags v2.6.0
Downloaded once_cell v1.20.2
Downloaded hashbrown v0.14.5
Downloaded rusqlite v0.32.1
Downloaded zerocopy v0.7.35
Downloaded vcpkg v0.2.15
Downloaded libsqlite3-sys v0.30.1
Downloaded 15 crates (6.1 MB) in 2.49s (largest was `libsqlite3-sys` at 5.1 MB)
Compiling version_check v0.9.5
Compiling once_cell v1.20.2
Compiling vcpkg v0.2.15
Compiling cfg-if v1.0.0
Compiling zerocopy v0.7.35
Compiling pkg-config v0.3.31
Compiling ahash v0.8.11
Compiling fallible-iterator v0.3.0
Compiling smallvec v1.13.2
Compiling fallible-streaming-iterator v0.1.9
Compiling libsqlite3-sys v0.30.1
Compiling bitflags v2.6.0
Compiling hashbrown v0.14.5
Compiling hashlink v0.9.1
Compiling rusqlite v0.32.1
error[E0658]: `c".."` literals are experimental
--> /home/ore/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rusqlite-0.32.1/src/lib.rs:1934:44
|
1934 | let r = unsafe { ffi::sqlite3_open(c":memory:".as_ptr(), &mut handle) };
| ^^^^^^^^^^^
|
= note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information
For more information about this error, try `rustc --explain E0658`.
error: could not compile `rusqlite` (lib) due to previous error
~/rust/sql$ sqlite3
Command 'sqlite3' not found, but can be installed with:
sudo apt install sqlite3
~/rust/sql$ sudo apt install sqlite3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libsqlite3-0
Suggested packages:
sqlite3-doc
The following NEW packages will be installed:
sqlite3
The following packages will be upgraded:
libsqlite3-0
1 upgraded, 1 newly installed, 0 to remove and 214 not upgraded.
Need to get 1409 kB of archives.
After this operation, 2803 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libsqlite3-0 amd64 3.31.1-4ubuntu0.6 [549 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 sqlite3 amd64 3.31.1-4ubuntu0.6 [860 kB]
Fetched 1409 kB in 2s (610 kB/s)
(Reading database ... 73442 files and directories currently installed.)
Preparing to unpack .../libsqlite3-0_3.31.1-4ubuntu0.6_amd64.deb ...
Unpacking libsqlite3-0:amd64 (3.31.1-4ubuntu0.6) over (3.31.1-4ubuntu0.5) ...
Selecting previously unselected package sqlite3.
Preparing to unpack .../sqlite3_3.31.1-4ubuntu0.6_amd64.deb ...
Unpacking sqlite3 (3.31.1-4ubuntu0.6) ...
Setting up libsqlite3-0:amd64 (3.31.1-4ubuntu0.6) ...
Setting up sqlite3 (3.31.1-4ubuntu0.6) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
~/rust/sql$ cargo build
Compiling rusqlite v0.32.1
error[E0658]: `c".."` literals are experimental
--> /home/ore/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rusqlite-0.32.1/src/lib.rs:1934:44
|
1934 | let r = unsafe { ffi::sqlite3_open(c":memory:".as_ptr(), &mut handle) };
| ^^^^^^^^^^^
|
= note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information
For more information about this error, try `rustc --explain E0658`.
error: could not compile `rusqlite` (lib) due to previous error
~/rust/sql$ cargo build
error: failed to parse manifest at `/home/ore/rust/sql/Cargo.toml`
Caused by:
TOML parse error at line 9, column 1
|
9 | //rusqlite = "0.32.1"
| ^
invalid key
~/rust/sql$ cargo build
Updating crates.io index
Downloaded bitflags v1.3.2
Downloaded shlex v1.3.0
Downloaded fallible-iterator v0.2.0
Downloaded hashlink v0.7.0
Downloaded ahash v0.7.8
Downloaded getrandom v0.2.15
Downloaded memchr v2.7.4
Downloaded hashbrown v0.11.2
Downloaded cc v1.1.31
Downloaded rusqlite v0.25.4
Downloaded libsqlite3-sys v0.22.2
Downloaded libc v0.2.161
Downloaded 12 crates (3.7 MB) in 1.56s (largest was `libsqlite3-sys` at 2.3 MB)
Compiling libc v0.2.161
Compiling shlex v1.3.0
Compiling ahash v0.7.8
Compiling memchr v2.7.4
Compiling cc v1.1.31
Compiling fallible-iterator v0.2.0
Compiling bitflags v1.3.2
Compiling libsqlite3-sys v0.22.2
Compiling getrandom v0.2.15
Compiling hashbrown v0.11.2
Compiling hashlink v0.7.0
Compiling rusqlite v0.25.4
Compiling sql v0.1.0 (/home/ore/rust/sql)
error: couldn't read src/main.rs: stream did not contain valid UTF-8
error: could not compile `sql` (bin "sql") due to previous error
~/rust/sql$ cargo build
Compiling sql v0.1.0 (/home/ore/rust/sql)
warning: fields `id`, `name`, and `population` are never read
--> src/main.rs:6:2
|
5 | struct City {
| ---- fields in this struct
6 | id: String,
| ^^
7 | name: String,
| ^^^^
8 | population: i32,
| ^^^^^^^^^^
|
= note: `City` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
= note: `#[warn(dead_code)]` on by default
warning: `sql` (bin "sql") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 2.42s
~/rust/sql$ ls
Cargo.lock Cargo.toml src target
~/rust/sql$ sqlite3 test.sqlite3
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> .table
sqlite> ls
...>
...> ;
Error: near "ls": syntax error
sqlite> .ls
Error: unknown command or invalid arguments: "ls". Enter ".help" for help
sqlite> .quit
~/rust/sql$ ls
Cargo.lock Cargo.toml src target test.sqlite3
~/rust/sql$ cargo run test.sqlite3
warning: fields `id`, `name`, and `population` are never read
--> src/main.rs:6:2
|
5 | struct City {
| ---- fields in this struct
6 | id: String,
| ^^
7 | name: String,
| ^^^^
8 | population: i32,
| ^^^^^^^^^^
|
= note: `City` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
= note: `#[warn(dead_code)]` on by default
warning: `sql` (bin "sql") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.09s
Running `target/debug/sql test.sqlite3`
*** start ***
City { id: "t0711", name: "郡山", population: 18954 }
City { id: "t0712", name: "会津若松", population: 83576 }
City { id: "t0713", name: "白河", population: 51769 }
*** end ***
~/rust/sql$ cargo build
Compiling sql v0.1.0 (/home/ore/rust/sql)
Finished dev [unoptimized + debuginfo] target(s) in 1.51s
~/rust/sql$ cargo run test.sqlite3
Finished dev [unoptimized + debuginfo] target(s) in 0.06s
Running `target/debug/sql test.sqlite3`
*** start ***
test.sqlite3
*** end ***
~/rust/sql$ sqlite3 test.sqlite3
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> select * from cities;
t0711|郡山|38415|1956-5-15
t0712|会津若松|57926|1956-6-8
t0713|白河|98123|1956-8-17
t0714|福島|63259|1956-1-21
t0715|喜多方|21748|1956-9-12
t0716|二本松|51924|1956-7-5
t0717|いわき|97125|1956-9-12
t0718|相馬|63219|1956-3-22
t0719|須賀川|25781|1956-11-30
sqlite>
以上