Instantly share code, notes, and snippets.

View playground.rs
enum Void {}
extern {
fn write(file: i32, buffer: *const Void, count: usize);
}
fn main() {
unsafe { write(1, "foo\0".as_ptr() as *const Void, 3) };
}
View playground.rs
#![feature(no_core)] #![no_core]
#[macro_use] extern crate std;
use std::fmt;
fn main() { println!("Hello world!"); }
View playground.rs
#[no_mangle]
pub fn write(message: &str) {}
fn main() {
write("hello world");
println!("hello world");
}
View playground.rs
#![feature(unsize, nll)]
use std::ptr;
use std::mem::{self, ManuallyDrop};
use std::marker::{PhantomData, Unsize};
struct PartialArray<T, A>
where
A: Unsize<[T]>
{
View playground.rs
use std::fs::File;
use std::io::prelude::*;
use std::thread;
use std::sync::Arc;
extern crate regex;
use regex::Regex;
const NUMBER_OF_THREADS: usize = 5;
struct ThreadData {
vector_of_strings: Vec<String>,
terms: Vec<& 'static str>,
View playground.rs
fn main() {
println!("Hello, world!");
}
View playground.rs
#[no_mangle]
pub fn write(message: &str, color: u8, len: u8, slice: &mut [u8]) {
let bytes = message.bytes().take(len as usize);
let mut out = slice.iter_mut();
bytes.for_each(|byte| {
*out.next().unwrap() = byte;
*out.next().unwrap() = color;
})
}
View playground.rs
struct Foo;
const Foo: Foo = Foo(); // does not compile due to name clash
fn main() {}
View playground.rs
fn main() {
println!("Hello, world!");
}
View playground.rs
#![feature(unsize)]
use std::ptr;
use std::mem::{self, ManuallyDrop};
use std::marker::{PhantomData, Unsize};
struct PartialArray<T, A>
where
A: Unsize<[T]>
{