1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

wslでrust その2

Posted at

概要

wslでrustやってみた。
systemにrandが、無いらしい。
randクレートを呼びつけて、使ってみた。
zundokoやってみた。

操作手順

~$ ls
elixir	fpga	git	osero.livemd	project	rust	test.db
~$ cd rust

~/rust$ cargo new zundoko
		 Created binary (application) `zundoko` package
~/rust$ cd zundoko

~/rust/zundoko$ cargo add rand
		Updating crates.io index
			Adding rand v0.8.5 to dependencies.
						 Features:
						 + alloc
						 + getrandom
						 + libc
						 + rand_chacha
						 + std
						 + std_rng
						 - log
						 - min_const_gen
						 - nightly
						 - packed_simd
						 - serde
						 - serde1
						 - simd_support
						 - small_rng
		Updating crates.io index
~/rust/zundoko$ explorer.exe .
~/rust/zundoko$ explorer.exe .

~/rust/zundoko$ cargo build
	Downloaded rand_core v0.6.4
	Downloaded proc-macro2 v1.0.89
	Downloaded rand_chacha v0.3.1
	Downloaded byteorder v1.5.0
	Downloaded getrandom v0.2.15
	Downloaded zerocopy-derive v0.7.35
	Downloaded ppv-lite86 v0.2.20
	Downloaded quote v1.0.37
	Downloaded unicode-ident v1.0.13
	Downloaded rand v0.8.5
	Downloaded zerocopy v0.7.35
	Downloaded syn v2.0.85
	Downloaded libc v0.2.161
	Downloaded 13 crates (1.6 MB) in 0.91s
	 Compiling proc-macro2 v1.0.89
	 Compiling unicode-ident v1.0.13
	 Compiling libc v0.2.161
	 Compiling byteorder v1.5.0
	 Compiling cfg-if v1.0.0
	 Compiling quote v1.0.37
	 Compiling syn v2.0.85
	 Compiling getrandom v0.2.15
	 Compiling rand_core v0.6.4
	 Compiling zerocopy-derive v0.7.35
	 Compiling zerocopy v0.7.35
	 Compiling ppv-lite86 v0.2.20
	 Compiling rand_chacha v0.3.1
	 Compiling rand v0.8.5
	 Compiling zundoko v0.1.0 (/home/ore/rust/zundoko)
error: couldn't read src/main.rs: stream did not contain valid UTF-8

error: could not compile `zundoko` (bin "zundoko") due to previous error

~/rust/zundoko$ cargo build
	 Compiling zundoko v0.1.0 (/home/ore/rust/zundoko)
		Finished dev [unoptimized + debuginfo] target(s) in 1.04s
  
~/rust/zundoko$ cargo run
		Finished dev [unoptimized + debuginfo] target(s) in 0.10s
		 Running `target/debug/zundoko`
ズン ズン ズン ズン ドコ	キ・ヨ・シ!

~/rust/zundoko$ cargo run
		Finished dev [unoptimized + debuginfo] target(s) in 0.22s
		 Running `target/debug/zundoko`
ズン ズン ズン ドコ ズン ドコ ドコ ドコ ドコ ズン ズン ズン ズン ズン ドコ	キ・ヨ・シ!
~/rust/zundoko$




サンプルコード


use rand::Rng;

fn main() {
	let mut zcnt = 0;
	let mut rng = rand::thread_rng();
	loop 
	{
		let zd = rng.gen();
		print!("{} ", if zd {"ズン"} else {"ドコ"});
		if zd 
		{
			zcnt += 1
		} 
		else if zcnt >= 4 
		{
			break
		} 
		else 
		{
			zcnt = 0
		}
	}
	println!(" キ・ヨ・シ!");
}





以上

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?