1
0
Fork
You've already forked option-ext
0
extends Option with additional operations
  • Rust 100%
Nick Mathewson 20079f3194 Add explicit MPL-2.0 licence notice "Exhibit A"
Unlike most other Free Software licences, the MPL explicitly says it
applies only to files with a specific notice:
 1.4. "Covered Software"
	means Source Code Form to which the initial Contributor has attached
	the notice in Exhibit A, the Executable Form of such Source Code
	Form, and Modifications of such Source Code Form, in each case
	including portions thereof.
Unfortunately, this means that copying the MPL text into tree, and
setting the "license" Cargo option, leaves an ambiguous situation.
One might presume that the intent was to actually *use* the MPL for
the whole project, but the legal licence text explicitly rejects that.
Thankfully, according to the licence text, it is not actually
necessary to add the notice to *every* file:
 If it is not possible or desirable to put the notice in a particular
 file, then You may include the notice in a location (such as a LICENSE
 file in a relevant directory) where a recipient would be likely to look
 for such a notice.
So clarify this situation by adding one central explicit copy of the
MPL "Exhibit A" text, and declare it to apply to everything.
Putting it in Cargo.toml puts it next to the "license =" tag. Another
possibility would be `README.md` but IMO this legal technicality
doesn't really warrant such exposure.
(Putting it in the LICENCE file, as the text itself suggests, would
mean either (i) renaming the verbatim copy of the MPL 2.0 and writing
a new file or (ii) adding it as a rubric to the top of the MPL 2.0
text in LICENCE - resulting in a LICENCE file which is not identical
to the usual MPL-2.0 text file. Neither of those seem desirable.)
2023年05月23日 20:32:30 +00:00
src release 0.2.0, adds map_or2 and map_or_else2 2023年01月11日 20:48:50 +01:00
.gitignore initial commit 2022年01月17日 17:10:37 +01:00
Cargo.lock release 0.2.0, adds map_or2 and map_or_else2 2023年01月11日 20:48:50 +01:00
Cargo.toml Add explicit MPL-2.0 licence notice "Exhibit A" 2023年05月23日 20:32:30 +00:00
LICENSE.txt initial commit 2022年01月17日 17:10:37 +01:00
README.md use more modern badge style 2023年04月04日 14:09:48 +02:00

crates.io API documentation actively developed License: MPL-2.0

option-ext

Introduction

This crate extends Option with additional methods, currently:

  • contains
  • map_or2 (as a replacement for map_or)
  • map_or_else2 (as a replacement for map_or_else)

Its sister crate is result-ext, which extends Result.

Requirements

Rust 1.0 or newer.

Usage

Dependency

Add the library as a dependency to your project by inserting

option-ext = "0.2.0"

into the [dependencies] section of your Cargo.toml file.

Example

useoption_ext::OptionExt;fn example_contains(){letx: Option<u32>=Some(2);assert_eq!(x.contains(&2),true);letx: Option<u32>=Some(3);assert_eq!(x.contains(&2),false);letx: Option<u32>=None;assert_eq!(x.contains(&2),false);}fn example_map_or2(){letx=Some("bar");assert_eq!(x.map_or2(|v|v.len(),42),3);letx: Option<&str>=None;assert_eq!(x.map_or2(|v|v.len(),42),42);}fn example_map_or_else2(){letk=23;letx=Some("bar");assert_eq!(x.map_or_else2(|v|v.len(),||2*k),3);letx: Option<&str>=None;assert_eq!(x.map_or_else2(|v|v.len(),||2*k),46);}