1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
//! `use std_prelude::*` so you can be ready to code! //! //! # Traits //! Not having common traits imported is one of the most annoying gotchas in rust when coming from //! other languages. When you are used to the language, you expect the methods you are used to to //! always work... not so. Using `Vec::from_iter` is extremely common, but you must first import //! the `FromIterator` trait. //! //! The following are the traits that are exported and why: //! //! - `std::ascii::AsciiExt`: adds the `to_ascii_uppercase` onto `&str` types. //! - `std::fmt::Debug`: allows you to define Debug manually. //! - `std::hash::{Hash, Hasher}`: allows you to easily implement `Hash` on your types. //! - `std::fmt::Write as FmtWrite`: adds `write_str` onto byte buffers (such as `String`). Renamed //! `FmtWrite` to avoid conflict with `std::io::Write` //! - `std::io::BufRead`: the `BufRead` trait allows you to use the methods associated with //! the `BufReader` struct. //! - `std::io::Read`: allows you to use `file.read()` //! - `std::io::Seek`: allows you to use `file.seek()` //! - `std::io::Write as IoWrite`: allows you to use `file.write()` and `file.write_all()`. Renamed //! `IoWrite` to avoid conflict with `std::fmt::Write` //! - `std::ops::{Deref, DerefMut}`: allows deref through `*v` and also enables Deref coercions //! - `std::str::FromStr`: allows you to use `type::from_str` constructor for several types. This //! is what is implicitly called with `str::parse<_>()` //! //! # structs //! These are extremely commonly used types and it is annoying to have to reimport them all the //! time. //! //! - `std::collections::{BTreeMap, HashMap, HashSet}`: ordered-dict, dict and set //! - `std::cmp::{Ord, PartialOrd, Ordering}`: for defining the `Ord` and `PartialOrd` trait, //! as well as working with types that use them. //! - `std::ffi::OsString`: os agnostic (non unicode) string type `std::path::PathBuf` uses this. //! - `std::fs::File`: for opening files. //! - `File::open` to open a file for reading //! - `File::write` to open a file for writing //! - `std::fs::OpenOptions` for more file opening options //! - `std::fs::ReadDir`: to iterate over the entries in a directory. //! - `std::io::BufReader`: the BufRead struct wraps `io::Read` using a buffer reducing the number //! of OS calls and giving helpful methods //! - `read_line()`: read a single line //! - `lines()`: return an iterator over all lines. //! - `split(byte: u8)`: return an iterator which splits at the chosen byte. //! - `std::io::BufWriter`: similar to `BufReader`, buffers writes to reduce the number of calls to //! the OS. Provides no new methods. //! - `std::path::{Path, PathBuf}`: specifies an os path. //! - `std::rc::Rc`: reference counted pointer //! - `std::sync::Arc`: atomically reference counted pointer //! - `std::sync::Mutex`: mutual exclusion primitive for threading. //! - `std::sync::atomic::{AtomicBool, AtomicIsize, AtomicUsize}`: basic atomic types. Good for //! unique ids and lots of other use cases. //! - `std::sync::atomic::Ordering as AtomicOrdering`: necessary for performing operations on //! atomic types. For incrementing a counter use `val.fetch_add(1, AtomicOrdering::SeqCst)`. //! Renamed to not conflict with `std::cmp::Ordering`. //! - `std::sync::atomic::ATOMIC_USIZE_INIT`: initialized `AtomicUsize` of 0. Use with `static //! COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;` //! - `std::time::Duration`: an amount of time, used for `std::thread::sleep`. //! //! # functions //! These are mostly just "nice to have" functions and it is *really* unlikely that they would ever //! be overriden. //! //! - `std::mem::{size_of, size_of_val}`: get the size of a type. This is safe and common enough //! that it should be always available. //! - `std::thread::sleep`: put the thread to sleep for a `Duration`. //! - `std::thread::spawn`: spawn a function in a new thread. In rust this is memory safe, so it is //! nice to have it always available. //! //! # primitive-type modules //! The following modules are imported so that it is easy to access their relevant constants and //! constructors. //! //! - `u8 u16 u64 usize`: unsigned integer modules with `MAX` and `MIN` //! - `i8 i16 i64 isize`: signed integer modules with `MAX` and `MIN` //! - `f32 f64`: floating point modules with not just `MAX` and `MIN` but also `NAN`, `INFINITY`, //! etc as well as a `consts` module with basic mathematical constants like `PI` and `E`. //! - `str`: core string type with `from_utf8` function. // traits pub use std::ascii::AsciiExt; pub use std::cmp::{ Ord, PartialOrd, Ordering }; pub use std::fmt::{Debug, Write as FmtWrite}; pub use std::hash::{Hash, Hasher}; pub use std::io::{ BufRead, Read, Seek, SeekFrom, Write as IoWrite, }; pub use std::iter::FromIterator; pub use std::ops::{Deref, DerefMut}; pub use std::str::FromStr; // structs pub use std::collections::{BTreeMap, HashMap, HashSet}; pub use std::ffi::OsString; pub use std::fs::{ File, OpenOptions, ReadDir, }; pub use std::io::{ BufReader, BufWriter, }; pub use std::path::{Path, PathBuf}; pub use std::rc::Rc; pub use std::sync::{Arc, Mutex}; pub use std::sync::atomic::{ AtomicBool, AtomicIsize, AtomicUsize, Ordering as AtomicOrdering, ATOMIC_USIZE_INIT, }; pub use std::time::Duration; // functions pub use std::mem::{size_of, size_of_val}; pub use std::thread::{sleep, spawn}; // modules pub use std::u8; pub use std::u16; pub use std::u64; pub use std::usize; pub use std::i8; pub use std::i16; pub use std::i64; pub use std::isize; pub use std::f32; pub use std::f64; pub use std::str;