Skip to content

Instantly share code, notes, and snippets.

View carols10cents's full-sized avatar

Carol (Nichols || Goulding) carols10cents

View GitHub Profile
@carols10cents
carols10cents / playground.rs
Last active October 31, 2018 00:18 — forked from rust-play/playground.rs
Code shared from the Rust Playground
fn save_status(text: &str) -> Result<i64, &'static str> {
if text.len() > 200 {
return Err("status is too long, must be under 200 bytes");
}
let id = save_to_database(text)?;
// log id to server logs
@carols10cents
carols10cents / playground.rs
Last active February 16, 2017 02:59 — forked from anonymous/playground.rs
to break your brain again again
fn main() {
let z = 3;
let mut p = &z;
{
let x = 5;
p = &x;
p = &z;
}
@carols10cents
carols10cents / playground.rs
Created February 16, 2017 02:55 — forked from anonymous/playground.rs
to break your brain again
fn main() {
let z = 3;
let mut p = &z;
{
let x = 5;
p = &x;
}
}
@carols10cents
carols10cents / playground.rs
Last active February 16, 2017 02:52 — forked from anonymous/playground.rs
to break your brain with
fn main() {
let z = 3;
let r;
{
let x = 5;
let mut p = &x;
p = &z;
r = p;
}
@carols10cents
carols10cents / playground.rs
Last active May 29, 2016 21:15 — forked from anonymous/playground.rs
would clippy catch this copypasta?
fn main() {
let list = vec![0, 1, 2, 3, 4, 5];
let index = 3;
if true {
println!("the magic number is {}", list[index]);
} else {
let other_index = 5;
println!("the index is {}", other_index); // so you wouldn't get "unused variable other_index"
println!("the magic number is {}", list[index]);
@carols10cents
carols10cents / playground.rs
Created May 23, 2016 20:21 — forked from anonymous/playground.rs
Shared via Rust Playground
fn main() {
let mut a_vec = vec![1, 2, 3];
let mut a_slice = &mut a_vec[..];
let ref mut an_item = a_slice[0];
let mut foo = &mut an_item;
}
@carols10cents
carols10cents / playground.rs
Created March 17, 2016 00:12 — forked from anonymous/playground.rs
Shared via Rust Playground
// The error is that there's an unused generic G declared...
fn foo<G>() -> String {
String::from("hi")
}
fn main() {
println!("{}", foo());
// ^ but here is where the error message points to:
// error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
@carols10cents
carols10cents / playground.rs
Last active October 30, 2015 18:48 — forked from anonymous/playground.rs
fizzbuzz to illustrate conditionals
// Make these tests pass by filling in conditionals where the blanks currently are!
// Scroll down for hints :)
pub fn fizz_buzz(i: i32) -> String {
__________ {
"FizzBuzz".to_string()
} ___________ {
"Fizz".to_string()
} ___________ {
"Buzz".to_string()
@carols10cents
carols10cents / playground.rs
Created October 28, 2015 00:33 — forked from anonymous/playground.rs
Shared via Rust Playground
fn main() {
// I don't want this to have to be mut.
let v = vec![1, 2, 3];
// Not this either.
let w = vec![3, 4, 5];
// I want a newly allocated vec that is v + w.
let x = vec_concat(&v, &w);
println!("{:?}", x);
$ irb
1.9.3p327 :001 > logfile = File.new('some_file.txt', 'w')
=> #<File:some_file.txt>
1.9.3p327 :002 > logfile.write("my content")
=> 10
1.9.3p327 :003 > quit
$ cat some_file.txt
my content
$ irb
1.9.3p327 :001 > logfile = File.new('some_file.txt', 'w')