Skip to content

Instantly share code, notes, and snippets.

The Rust Playground rust-play

Block or report user

Report or block rust-play

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rust-play
rust-play / playground.rs
Created Jul 16, 2019
Code shared from the Rust Playground
View playground.rs
#![allow(unused)]
fn main() {
let input = vec![vec![8, 7, 9], vec![6, 7, 6], vec![3, 2, 5]];
for (i, row) in input.iter().enumerate(){
let max = row.iter().max();
println!("\ni = {}", i);
println!("row = {:?}", row);
println!("max = {:?}\n", max);
for (j, col) in row.iter().enumerate() {
@rust-play
rust-play / playground.rs
Created Jul 16, 2019
Code shared from the Rust Playground
View playground.rs
#![allow(dead_code)]
use std::mem::size_of;
impl S1 {
pub fn as_bytes(&self) -> &[u8] {
let ptr = self as *const Self as *const u8;
let len = std::mem::size_of::<Self>();
unsafe { std::slice::from_raw_parts(ptr, len) }
}
@rust-play
rust-play / playground.rs
Created Jul 16, 2019
Code shared from the Rust Playground
View playground.rs
let echo_future = ClientBuilder::new("wss://echo.websocket.org").unwrap()
.async_connect(None)
.and_then(|(s, _)| s.send(Message::text("sup").into()))
.and_then(|s| s.into_future().map_err(|e| e.0))
.map(|(m, _)| {
assert_eq!(m, Some(Message::text("sup").into()))
});
tokio::run(echo_future);
@rust-play
rust-play / playground.rs
Created Jul 16, 2019
Code shared from the Rust Playground
View playground.rs
#![allow(unused)]
fn main() {
let input = vec![vec![8, 7, 9], vec![6, 7, 6], vec![3, 2, 5]];
for (i, row) in input.iter().enumerate(){
let max = row.iter().max();
println!("\ni = {}", i);
println!("row = {:?}", row);
println!("max = {:?}\n", max);
for (j, val) in row.iter().enumerate() {
@rust-play
rust-play / playground.rs
Created Jul 16, 2019
Code shared from the Rust Playground
View playground.rs
#[derive(Debug)]
#[repr(C)]
struct MyStruct<T, U> {
height: Option<T>,
width: Option<T>,
age: u32,
othertype: U,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
@rust-play
rust-play / playground.rs
Created Jul 16, 2019
Code shared from the Rust Playground
View playground.rs
fn reverse(input: &str) -> String {
let string = input.to_string();
string
.split(' ')
.map(|word| {
if word.len() < 5 {
word.to_string()
} else {
word.chars().rev().collect()
}
@rust-play
rust-play / playground.rs
Created Jul 16, 2019
Code shared from the Rust Playground
View playground.rs
use std::sync::Arc;
use tokio::prelude::*;
use tokio::net::TcpStream;
use tokio::sync::mpsc;
struct Message {
buf: Vec<u8>,
}
@rust-play
rust-play / playground.rs
Created Jul 16, 2019
Code shared from the Rust Playground
View playground.rs
trait Key {
fn key() -> &'static str;
}
trait Model where Self: Key {
fn get() {
println!("Getting {}", Self::key());
}
}
@rust-play
rust-play / playground.rs
Created Jul 16, 2019
Code shared from the Rust Playground
View playground.rs
#![allow(unreachable_code)]
fn main() {
println!("{:?}", {
{ let a = [1,2,3]; a.get(10..) }
});
}
@rust-play
rust-play / playground.rs
Created Jul 16, 2019
Code shared from the Rust Playground
View playground.rs
#![allow(unreachable_code)]
fn main() {
println!("{:?}", {
{ let a = [1, 2, 3, 4]; if a.len() > 3 { println!("{}", a[3] } }
});
}
You can’t perform that action at this time.