코딩Coding/Rust연습
-
Rust연습)벡터안에 0 을 10개 넣기코딩Coding/Rust연습 2023. 6. 8. 17:39
fn main() { let v: Vec = vec![]; let v = vec![1, 2, 3, 4, 5]; let v = vec![0; 10]; // ten zeroes println!("{v:?}") } https://doc.rust-lang.org/stable/std/vec/index.html std::vec - Rust A contiguous growable array type with heap-allocated contents, written Vec . Vectors have O(1) indexing, amortized O(1) push (to the end) and O(1) pop (from the end). Vectors ensure they never allocate more than i..
-
Rust WebSocket구현 ChatGPT코딩Coding/Rust연습 2023. 5. 28. 20:54
WebSocketuse tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::net::TcpStream; use tokio_tungstenite::connect_async; use tokio_tungstenite::tungstenite::protocol::Message; #[tokio::main] async fn main() { // Connect to the WebSocket server let stream = TcpStream::connect("127.0.0.1:8080").await.unwrap(); let (mut ws_stream, _) = connect_async(stream).await.expect("Failed to connect to WebSock..
-
rust연습❤️let mut p: f64 = 16us.pow(2) as f64;코딩Coding/Rust연습 2022. 9. 12. 09:03
코드 출처 https://stackoverflow.com/questions/26993015/rust-error-unable-to-infer-enough-type-information-to-locate-the-impl-of-the-tr Rust error: unable to infer enough type information to locate the impl of the trait I don't quite understand why this is ok use std::num; fn main() { let mut p_: int = num::pow(16, 2); let mut p: f64 = p_ as f64; } but this is failing use std::num; fn main() { let.....
-
Rust☆연습_Traits_part2코딩Coding/Rust연습 2022. 9. 11. 14:00
// Dungeons and Dragons struct Dwarf { name: String, } struct Elf { name: String, } struct HalfElf { name: String, } struct HalfOrc { name: String, } struct Human { name: String, } impl Constitution for Elf {} impl Constitution for Human {} // The constitution bonus for a dwarf is 2 impl Constitution for Dwarf { fn constitution_bonus(&self) -> u8 { 2 } } impl Constitution for HalfOrc { fn consti..
-
Rust☆연습(Traits)_part1코딩Coding/Rust연습 2022. 9. 11. 11:21
// Dungeons and Dragons struct Dwarf { name: String, } struct Elf { name: String, } struct HalfOrc { name: String, } struct Human { name: String, } impl Constitution for Elf {} impl Constitution for Human {} // The constitution bonus for a dwarf is 2 impl Constitution for Dwarf { fn constitution_bonus(&self) -> u8 { 2 } } impl Constitution for HalfOrc { fn constitution_bonus(&self) -> u8 { 1 } }..
-
러스트연습숫자가 0부터 계속 올라감 계속 그 자리에서 출력코딩Coding/Rust연습 2022. 8. 14. 00:09
use std::io::Write; use std::thread; use std::time; fn main() { let mut bun: u64 = 0; loop { print!("\r{}", bun); std::io::stdout().flush().unwrap(); bun += 1; thread::sleep(time::Duration::from_millis(100)); } } 숫자가 0부터 계속 올라감 계속 그 자리에서 출력 cargo run Compiling char v0.1.0 (/Users/globalyoung/Documents/test/rust/char) Finished dev [unoptimized + debuginfo] target(s) in 0.15s Running `target/debug..
-
Rust연습_H가 같은줄에 출력에서 앞으로 계속 쌓임.코딩Coding/Rust연습 2022. 8. 14. 00:06
use std::io::Write; use std::time::Duration; fn main() { let ch = 'H' as u8; for _ in 0..20 { let buff = vec![ch]; std::io::stdout().write(&buff).unwrap(); std::io::stdout().flush().unwrap(); std::thread::sleep(Duration::from_millis(1000)); } } 결과 cargo run Compiling char v0.1.0 (/Users/globalyoung/Documents/test/rust/char) Finished dev [unoptimized + debuginfo] target(s) in 0.17s Running `targe..
-
Rust연습❤️물어보고 출력 무한 loop코딩Coding/Rust연습 2022. 8. 14. 00:02
use std::io::{self, Write}; fn main() { let mut stdin = io::stdin(); let input = &mut String::new(); loop { input.clear(); print!("Your age: "); io::stdout().flush(); stdin.read_line(input); print!("{}", input); } } warning: `char` (bin "char") generated 3 warnings Finished dev [unoptimized + debuginfo] target(s) in 0.16s Running `target/debug/char` Your age: 324 324 Your age: 11 11 Your age: q ..