Plugin https://github.com/fatih/vim-go
Tutorial https://github.com/fatih/vim-go-tutorial
Vimrc https://github.com/fatih/dotfiles/blob/master/vimrc
- File
:GoRun %
- Package
:GoRun
- Debug
:GoDebugStart
# Script to generate a new block every minute | |
# Put this script at the root of your unpacked folder | |
#!/bin/bash | |
echo "Generating a block every minute. Press [CTRL+C] to stop.." | |
address=`./bin/bitcoin-cli getnewaddress` | |
while : | |
do |
fn main() { | |
let s = String::from("book"); | |
let ss = pluralize(s.clone()); | |
println!("One {}, many {}", s, ss); | |
} | |
fn pluralize(s: String) -> String { | |
// Can't push_str directly onto s as s is not mutable |
use std::fmt; | |
fn main() -> Result<(), &'static str> { | |
let b = vec![0x64, 0x61, 0x76, 0x65]; | |
println!("{}", b.to_hex()); | |
Ok(()) | |
} | |
trait ToHex { | |
fn to_hex(&self) -> String; |
fn main() { | |
// Match is an expression as well as a statement. This example shows how | |
// a variable is set based on an Option enum. | |
// ------------------------------------------ | |
let msg_option = Some("+++MELON MELON MELON+++"); // Some variant | |
let msg_option_empty = None; // None variant | |
let msg = match msg_option { | |
Some(m) => m, // m is the unwrapped data from the option |
fn main() { | |
// If `option` is Some<T>, unwrap it and stick the value in `x`. | |
if let Some(x) = option { | |
foo(x); | |
} | |
} |
fn main() { | |
// If x has a value, unwrap it and set y to it's value. | |
// Otherwise, set y to a default. | |
// ------------------------------------------------------------------------ | |
// let x = Some(11); // Uncomment to test | |
let x = None; | |
let y; | |
if x.is_some() { | |
y = x.unwrap(); |
/// Notes ownership and borrowing. | |
fn main() -> Result<(), &'static str> { | |
let mut a = [1,2,3,4]; | |
println!("{:?}", a); | |
{ | |
let b = &mut a[0..2]; | |
// You can't access a at this point because it has been mutably borrowed | |
// from. The following line won't compile, with the error message: | |
// `cannot borrow `a` as immutable because it is also borrowed as mutable`: | |
// println!("a: {:?}", a); |
//! Examples for `unwrap_or_else()` | |
use std::process; | |
fn func(in_num: u8) -> Option<&'static str> { | |
if in_num % 2 != 0 { | |
return None; | |
} | |
Some("even") | |
} |
//! Examples for `unwrap_or_else()` | |
use std::process; | |
fn func(in_num: u8) -> Option<&'static str> { | |
if in_num % 2 != 0 { | |
return None; | |
} | |
Some("even") | |
} |