Skip to content

Commit a08843a

Browse files
committed
add license and boilerplate
1 parent a080be9 commit a08843a

File tree

8 files changed

+307
-65
lines changed

8 files changed

+307
-65
lines changed

.travis.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
language: rust
2+
3+
branches:
4+
only:
5+
# This is where pull requests from "bors r+" are built.
6+
- staging
7+
# This is where pull requests from "bors try" are built.
8+
- trying
9+
10+
rust:
11+
- stable
12+
- beta
13+
- nightly
14+
15+
matrix:
16+
allow_failures:
17+
- rust: nightly
18+
19+
cache: cargo
20+
21+
notifications:
22+
email:
23+
on_success: never
24+
25+
script:
26+
- RUST_BACKTRACE=1 cargo test --verbose --all -- --nocapture

Cargo.toml

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
[package]
2-
authors = ["Garrett Berg <[email protected]>"]
3-
name = "ergo_prelude"
2+
authors = ["Garrett Berg <[email protected]>"]
3+
description = "items that could be in the standard library, part of the ergo ecosystem"
4+
documentation = "https://docs.rs/ergo_std"
5+
keywords = [
6+
"ergo",
7+
"std",
8+
]
9+
license = "MIT OR Apache-2.0"
10+
name = "ergo_std"
11+
readme = "README.md"
12+
repository = "https://github.com/rust-crates/ergo_std"
413
version = "0.1.0"
514

615
[dependencies]

LICENSE-APACHE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2018 Garrett Berg, [email protected]
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

LICENSE-MIT

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Garrett Berg, [email protected]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ergo_std: items that could be in the standard library.
2+
3+
[![Build Status](https://travis-ci.org/vitiral/ergo_std.svg?branch=windows)](https://travis-ci.org/vitiral/ergo_std)
4+
[![Build status](https://ci.appveyor.com/api/projects/status/vgis54solhygre0n?svg=true)](https://ci.appveyor.com/project/vitiral/path-abs)
5+
[![Docs](https://docs.rs/ergo_std/badge.svg)](https://docs.rs/ergo_std)
6+
7+
**See the [library docs](https://docs.rs/ergo_std) for more information**
8+
9+
10+
# LICENSE
11+
The source code in this repository is Licensed under either of
12+
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
13+
http://www.apache.org/licenses/LICENSE-2.0)
14+
- MIT license ([LICENSE-MIT](LICENSE-MIT) or
15+
http://opensource.org/licenses/MIT)
16+
17+
at your option.
18+
19+
Unless you explicitly state otherwise, any contribution intentionally submitted
20+
for inclusion in the work by you, as defined in the Apache-2.0 license, shall
21+
be dual licensed as above, without any additional terms or conditions.

appveyor.yml

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Appveyor configuration template for Rust using rustup for Rust installation
2+
# https://github.com/starkat99/appveyor-rust
3+
4+
## Operating System (VM environment) ##
5+
6+
# Rust needs at least Visual Studio 2013 Appveyor OS for MSVC targets.
7+
os: Visual Studio 2015
8+
9+
# Bors configuration
10+
branches:
11+
only:
12+
# This is where pull requests from "bors r+" are built.
13+
- staging
14+
# This is where pull requests from "bors try" are built.
15+
- trying
16+
17+
## Build Matrix ##
18+
19+
# This configuration will setup a build for each channel & target combination (12 windows
20+
# combinations in all).
21+
#
22+
# There are 3 channels: stable, beta, and nightly.
23+
#
24+
# Alternatively, the full version may be specified for the channel to build using that specific
25+
# version (e.g. channel: 1.5.0)
26+
#
27+
# The values for target are the set of windows Rust build targets. Each value is of the form
28+
#
29+
# ARCH-pc-windows-TOOLCHAIN
30+
#
31+
# Where ARCH is the target architecture, either x86_64 or i686, and TOOLCHAIN is the linker
32+
# toolchain to use, either msvc or gnu. See https://www.rust-lang.org/downloads.html#win-foot for
33+
# a description of the toolchain differences.
34+
# See https://github.com/rust-lang-nursery/rustup.rs/#toolchain-specification for description of
35+
# toolchains and host triples.
36+
#
37+
# Comment out channel/target combos you do not wish to build in CI.
38+
#
39+
# You may use the `cargoflags` and `RUSTFLAGS` variables to set additional flags for cargo commands
40+
# and rustc, respectively. For instance, you can uncomment the cargoflags lines in the nightly
41+
# channels to enable unstable features when building for nightly. Or you could add additional
42+
# matrix entries to test different combinations of features.
43+
environment:
44+
matrix:
45+
46+
### MSVC Toolchains ###
47+
48+
# Stable 64-bit MSVC
49+
- channel: stable
50+
target: x86_64-pc-windows-msvc
51+
# Stable 32-bit MSVC
52+
- channel: stable
53+
target: i686-pc-windows-msvc
54+
# # Beta 64-bit MSVC
55+
# - channel: beta
56+
# target: x86_64-pc-windows-msvc
57+
# # Beta 32-bit MSVC
58+
# - channel: beta
59+
# target: i686-pc-windows-msvc
60+
# # Nightly 64-bit MSVC
61+
# - channel: nightly
62+
# target: x86_64-pc-windows-msvc
63+
# #cargoflags: --features "unstable"
64+
# # Nightly 32-bit MSVC
65+
# - channel: nightly
66+
# target: i686-pc-windows-msvc
67+
# #cargoflags: --features "unstable"
68+
69+
### GNU Toolchains ###
70+
71+
# Stable 64-bit GNU
72+
- channel: stable
73+
target: x86_64-pc-windows-gnu
74+
# Stable 32-bit GNU
75+
- channel: stable
76+
target: i686-pc-windows-gnu
77+
# # Beta 64-bit GNU
78+
# - channel: beta
79+
# target: x86_64-pc-windows-gnu
80+
# # Beta 32-bit GNU
81+
# - channel: beta
82+
# target: i686-pc-windows-gnu
83+
# # Nightly 64-bit GNU
84+
# - channel: nightly
85+
# target: x86_64-pc-windows-gnu
86+
# #cargoflags: --features "unstable"
87+
# # Nightly 32-bit GNU
88+
# - channel: nightly
89+
# target: i686-pc-windows-gnu
90+
# #cargoflags: --features "unstable"
91+
92+
### Allowed failures ###
93+
94+
# See Appveyor documentation for specific details. In short, place any channel or targets you wish
95+
# to allow build failures on (usually nightly at least is a wise choice). This will prevent a build
96+
# or test failure in the matching channels/targets from failing the entire build.
97+
matrix:
98+
allow_failures:
99+
- channel: nightly
100+
101+
# If you only care about stable channel build failures, uncomment the following line:
102+
#- channel: beta
103+
104+
## Install Script ##
105+
106+
# This is the most important part of the Appveyor configuration. This installs the version of Rust
107+
# specified by the 'channel' and 'target' environment variables from the build matrix. This uses
108+
# rustup to install Rust.
109+
#
110+
# For simple configurations, instead of using the build matrix, you can simply set the
111+
# default-toolchain and default-host manually here.
112+
install:
113+
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
114+
- rustup-init -yv --default-toolchain %channel% --default-host %target%
115+
- set PATH=%PATH%;%USERPROFILE%\.cargo\bin
116+
- rustc -vV
117+
- cargo -vV
118+
119+
## Build Script ##
120+
121+
# 'cargo test' takes care of building for us, so disable Appveyor's build stage. This prevents
122+
# the "directory does not contain a project or solution file" error.
123+
build: false
124+
125+
# Uses 'cargo test' to run tests and build. Alternatively, the project may call compiled programs
126+
#directly or perform other testing commands. Rust will automatically be placed in the PATH
127+
# environment variable.
128+
test_script:
129+
- cargo test --verbose --all %cargoflags% -- --nocapture

bors.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
status = [
2+
"continuous-integration/travis-ci/push",
3+
"continuous-integration/appveyor/branch"
4+
]
5+
6+
# Uncomment this to use a two hour timeout.
7+
# The default is one hour.
8+
# timeout_sec = 7200

src/lib.rs

+78-63
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,79 @@
1-
// -------------------------------------
2-
// ----------- CUSTOM MACROS -----------
1+
//! **ergo_std**: items that could be in the standard library.
2+
//!
3+
//! This is the "core types" library as part of the [`ergo`] crates ecosystem. It contains useful
4+
//! types, traits and functions for general purpose programming projects which do not fall
5+
//! into the other [`ergo`] crates but which are boons to ergonomics and productivity.
6+
//!
7+
//! # How to Use
8+
//!
9+
//! ```rust
10+
//! #[macro_use] extern crate failure;
11+
//! extern crate serde;
12+
//! #[macro_use] extern crate serde_derive;
13+
//! #[macro_use] extern crate ergo_std;
14+
//! use ergo_std::*;
15+
//! # fn main() {
16+
//! # }
17+
//! ```
18+
//!
19+
//! > _As you notice, this crate does not include `serde` or `failure`. This is due to a bug
20+
//! > which makes it impossible for this crate to rexport their `#[derive(...)]` macros.
21+
//!
22+
//! # Exported Items
23+
//!
24+
//! The following crates and types are exported. See their docs for how to use them.
25+
//!
26+
//! - **[`std_prelude`]**: extends rust's additional prelude with commonly used types. The
27+
//! crate is well documented with justification and usecases for each type.
28+
//! - **[`lazy_static!`]**: the `lazy_static!` macro is the current standard way to create
29+
//! global variables and constants in a majority of crates.
30+
//! - **[`itertools`]**: the itertools prelude provides traits that extends rust's already
31+
//! extensive iterator API.
32+
//! - **[`maplit`]**: provides `hashmap!`, `hashset!`, `btreemap!` and `btreeset!` macros to
33+
//! compliment rust's existing `vec!` macro. These
34+
//! - **[`Regex`]**: the regular expression type from the `regex` crate.
35+
//!
36+
//! [`ergo`]: https://github.com/rust-crates/ergo
37+
//! [`std_prelude`]: ../std_prelude/index.html
38+
//! [`itertools`]: ../itertools/index.html
39+
//! [`lazy_static!`]: ../lazy_static/index.html
40+
//! [`maplit`]: ../maplit/index.html
41+
//! [`Regex`]: struct.Regex.html
42+
//!
43+
//! ### Special thanks
44+
//!
45+
//! The crates that are exported are:
46+
//!
47+
//! - [**std_prelude**](https://github.com/vitiral/std_prelude):
48+
//! Multi-producer multi-consumer channels for message passing
49+
//! - [**lazy_static**](TODO): TODO
50+
//! - [**itertools**](TODO): TODO
51+
//! - [**maplit**](TODO): TODO
52+
//! - [**regex**](TODO): TODO
53+
//!
54+
//! Consider supporting their development individually and starring them on github.
55+
//!
56+
//! ## Future crates
57+
//!
58+
//! The following crates will be added in the future:
59+
//!
60+
//! - `indexmap`: the current crate is `ordermap`, which is renaming itself
61+
//! `indexmap` and changing what `ordermap` is... it's confusing but it
62+
//! will be comming shortly
63+
64+
#[macro_use]
65+
pub extern crate itertools;
66+
#[macro_use]
67+
pub extern crate lazy_static;
68+
#[macro_use]
69+
pub extern crate maplit;
70+
pub extern crate std_prelude;
71+
pub extern crate regex;
72+
73+
pub use std_prelude::*;
74+
pub use itertools::prelude::*;
75+
pub use lazy_static::*;
76+
pub use itertools::Itertools;
77+
pub use maplit::*;
78+
pub use regex::Regex;
379

4-
#[macro_export]
5-
/// Use to take mutable ownership of _specific_ variables within a closure.
6-
///
7-
/// Closures try to be "smart" about how much scope they capture. If you don't mutate a variable
8-
/// they take `&var`, if you do mutate they take `&mut var`. However, if you require ownership you use
9-
/// `move`, i.e. `move || {... do stuff with var...}`... _right_?
10-
///
11-
/// The problem with `move` is that it moves _every_ variable that is referenced. If you only need
12-
/// to move _one_ variable it can be a pain. Interestingly, you can tell the compiler to only move
13-
/// _specific_ variables like so:
14-
///
15-
/// ```no_compile
16-
/// let x = x;
17-
/// let y = y;
18-
/// // ... etc
19-
/// ```
20-
///
21-
/// But this is quite silly and not obvious to someone who doesn't know about it. Instead, use the
22-
/// `own!` macro and your code will be self documenting.
23-
///
24-
/// > Note: this macro always does `let mut x = x` to mimick its primary usecase of closures
25-
/// > (which infer mutability automatically). If you require non-mutable ownership use `let x = x`
26-
/// > directly.
27-
///
28-
/// # Examples
29-
/// ```
30-
/// #[macro_use] extern crate std_prelude;
31-
///
32-
/// # fn main() {
33-
/// let y = vec![1, 2, 3];
34-
/// let mut x = vec![1, 2, 3];
35-
/// let z = vec![10];
36-
///
37-
/// // create scope in which we mutate `x`
38-
/// {
39-
/// let closure = || {
40-
/// own!(y, z);
41-
/// x.push(4); // mutate reference to x
42-
/// z.push(10);
43-
///
44-
/// println!("&x: {:?}", &x);
45-
/// println!("moved y: {:?}", y);
46-
/// println!("moved z: {:?}", z);
47-
/// };
48-
///
49-
/// closure();
50-
/// }
51-
///
52-
/// println!("&x after: {:?}", x); // We can still print x!
53-
/// // println!("y after: {:?}", y); // ERROR: use of moved value
54-
/// // println!("z after: {:?}", z); // ERROR: use of moved value
55-
/// # }
56-
/// ```
57-
macro_rules! own {
58-
( $( $x:ident ),* ) => {
59-
#[allow(unused_mut)]
60-
$(
61-
let mut $x = $x;
62-
)*
63-
};
64-
}

0 commit comments

Comments
 (0)