goish/lib.rs
1// goish: write Rust using Go idioms.
2//
3// use goish::prelude::*;
4//
5// fn divide(a: int64, b: int64) -> (int64, error) {
6// if b == 0 {
7// return (0, errors::New("divide by zero"));
8// }
9// (a / b, nil)
10// }
11//
12// fn main() {
13// Println!("hello", "world");
14//
15// let (q, err) = divide(10, 0);
16// if err != nil {
17// Println!("error:", err);
18// } else {
19// Printf!("q = %d\n", q);
20// }
21// }
22//
23// Cheat-sheet:
24//
25// Go goish
26// ─────────────────────────────── ──────────────────────────────────
27// int64 / float64 / byte / rune int64 / float64 / byte / rune
28// error error (a newtype, not Option)
29// nil nil (zero-value error)
30// if err != nil { ... } if err != nil { ... }
31// fmt.Println(a, b) fmt::Println!(a, b)
32// fmt.Printf("%d", n) fmt::Printf!("%d", n)
33// fmt.Sprintf("%s", s) fmt::Sprintf!("%s", s)
34// fmt.Fprintf(w, "%d", n) fmt::Fprintf!(w, "%d", n)
35// fmt.Errorf("bad: %s", e) fmt::Errorf!("bad: %s", e)
36// errors.New("msg") errors::New("msg")
37// errors.Wrap(err, "msg") errors::Wrap(err, "msg")
38// errors.Is(err, ErrX) errors::Is(&err, &ErrX)
39// errors.Unwrap(err) errors::Unwrap(err)
40
41#![allow(non_snake_case)]
42#![allow(non_camel_case_types)]
43#![allow(non_upper_case_globals)]
44
45pub mod bufio;
46pub mod bytes;
47pub mod chan;
48pub mod context;
49pub mod defer;
50pub mod errors;
51pub mod filepath;
52pub mod fmt;
53pub mod goroutine;
54pub mod io;
55pub mod log;
56pub mod math;
57pub mod os;
58pub mod range;
59pub mod sort;
60pub mod strconv;
61pub mod strings;
62pub mod sync;
63pub mod time;
64pub mod types;
65
66// Make Go primitive type names visible at the crate root so macros that
67// say `$crate::int` resolve correctly.
68pub use crate::types::*;
69
70pub mod prelude {
71 pub use crate::bufio;
72 pub use crate::bytes;
73 pub use crate::chan::Chan;
74 pub use crate::context;
75 pub use crate::errors::{self, error, nil};
76 pub use crate::filepath;
77 pub use crate::fmt;
78 pub use crate::io;
79 pub use crate::log;
80 pub use crate::math;
81 pub use crate::os;
82 pub use crate::sort;
83 pub use crate::strconv;
84 pub use crate::strings;
85 pub use crate::sync;
86 pub use crate::time;
87 pub use crate::types::*;
88 pub use crate::goroutine::Goroutine;
89 pub use crate::{
90 Errorf, Fprintf, Printf, Println, Sprintf,
91 append, chan, defer, delete, go, len, make, map, range, slice, stringer,
92 };
93}