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 Jun 25, 2019
Code shared from the Rust Playground
View playground.rs
use std::arch::x86_64::{__m256i, _mm256_set_epi32};
use std::arch::x86_64::_mm256_or_si256 as op_or;
use std::arch::x86_64::_mm256_srli_si256 as op_shift;
use std::arch::x86_64::_mm256_extract_epi32 as extract_i32;
#[allow(non_snake_case)]
unsafe fn or_collapse_to_u32(accumulator: __m256i) -> u32 {
let a___b___c___d___ = accumulator;
let ________a___b___ = op_shift(a___b___c___d___, 8);
let a___b___ac__bd__ = op_or(a___b___c___d___, ________a___b___);
@rust-play
rust-play / playground.rs
Created Jun 25, 2019
Code shared from the Rust Playground
View playground.rs
fn main() {
let lines = "привет\nмир\nhello\nworld".lines();
for (linenumber, line) in lines.enumerate() {
println!("{}: {}", linenumber, line);
}
}
@rust-play
rust-play / playground.rs
Created Jun 25, 2019
Code shared from the Rust Playground
View playground.rs
struct Context<'s>(&'s str);
struct Parser<'c, 's> {
context: &'c Context<'s>,
}
impl<'c, 's> Parser<'c, 's> {
fn parse(&self) -> Result<(), &'s str> {
Err(&self.context.0[1..])
}
@rust-play
rust-play / playground.rs
Created Jun 25, 2019
Code shared from the Rust Playground
View playground.rs
fn main() {
// Lesson one. All data in Rust is immutable by default.
// So this won't work unless we decalare with "let mut"
let s = String::from("Anna");
s = String::from("Coleman");
println!("Hello {}", s);
}
@rust-play
rust-play / playground.rs
Created Jun 25, 2019
Code shared from the Rust Playground
View playground.rs
#![allow(unreachable_code)]
fn main() {
println!("{:?}", {
let a = Box::new(0..5); for i in a { println!("{}", i); }
});
}
@rust-play
rust-play / playground.rs
Created Jun 25, 2019
Code shared from the Rust Playground
View playground.rs
struct Context<'s>(&'s str);
struct Parser<'c, 's> {
context: &'c Context<'s>,
}
impl<'c, 's> Parser<'c, 's> {
fn parse(&self) -> Result<(), &'s str> {
Err(&self.context.0[1..])
}
@rust-play
rust-play / playground.rs
Created Jun 25, 2019
Code shared from the Rust Playground
View playground.rs
macro_rules! doc_comment {
($x:expr) => {
#[doc = $x]
extern {}
};
// enum like types
($x:literal, $visibility:vis enum $ty_name:ident {
$($y:literal, $field:ident $(($($field_ty:ty),*))? ),* $(,)?
}) => {
#[doc = $x]
@rust-play
rust-play / playground.rs
Created Jun 25, 2019
Code shared from the Rust Playground
View playground.rs
fn iterate_with_iterator<T: std::fmt::Display, I: Iterator<Item = T>>(iter: I) {
for x in iter {
println!("{}", x);
}
}
fn iterate_with_boxed_iterator<'a, T: std::fmt::Display>(iter: Box<dyn Iterator<Item = T> + 'a>) {
for x in iter {
println!("{}", x);
}
@rust-play
rust-play / playground.rs
Created Jun 25, 2019
Code shared from the Rust Playground
View playground.rs
use std::mem;
macro_rules! offset_of {
($father:ty, $($field:tt)+) => ({
let root = mem::MaybeUninit::<$father>::uninit();
let base = &root as *const _ as usize;
// FIXME: This is wrong! We are triggering deref coercions
// here, which we can and should avoid.
@rust-play
rust-play / playground.rs
Created Jun 25, 2019
Code shared from the Rust Playground
View playground.rs
use std::mem;
macro_rules! offset_of {
($father:ty, $($field:tt)+) => ({
let root = mem::MaybeUninit::<$father>::uninit();
let base = &root as *const _ as usize;
// FIXME: This is wrong! We are triggering deref coercions
// here, which w should avoid.
You can’t perform that action at this time.