こんにちは、R&Dチームの齋藤(@aznhe21)です。 新オフィスは広くて快適です。
さて、本日4/8(金)にRust 1.60がリリースされました。 この記事ではRust 1.60での変更点を詳しく紹介します。
- ピックアップ
- 安定化されたAPIのドキュメント
- 変更点リスト
- 関連リンク
- さいごに
- ライセンス表記
ピックアップ
個人的に注目する変更点を「ピックアップ」としてまとめました。 全ての変更点を網羅したリストは変更点リストをご覧ください。
コンパイル時間を計測できるようになった
cargo buildなどビルド系のコマンドに--timingsフラグを指定することで、ビルド時に掛かった処理時間が出力されるようになりました。
ビルド時間を短縮したい場合に役立ちそうです。
cargo build --timings
手元にあった大きめのプロジェクトをビルドするとこのようになりました。 これ以外にもCPU使用率やクレートごとの所要時間をテーブルで表示する機能などもあるため、一度試してみてはいかがでしょうか。

機能(features)で名前空間付き・弱依存がサポートされた
これまでは任意選択のクレートを機能として使うことはできましたが、 クレートと同名の機能を定義することはできませんでした。
[dependencies]
chrono = "0.4"
serde = { version = "1.0", optional = true }
[features]
# `--features serde`でserdeとchronoのserde機能を同時に有効化したいが、これはできない
# serde = ["serde", "chrono/serde"]
Rust 1.60からはfeaturesセクションでクレート名部分にdep:serdeと指定することで、クレートと同名の機能を定義できるようになりました。
[dependencies]
chrono = "0.4"
serde = { version = "1.0", optional = true }
[features]
serde = ["dep:serde", "chrono/serde"]
また、dep:XXXで指定されたクレートは暗黙的機能として定義されなくなります。
例えば下記Cargo.tomlを使用した場合、ravifとrgbは--featuresに指定することができません。
[dependencies]
ravif = { version = "0.6.3", optional = true }
rgb = { version = "0.8.25", optional = true }
[features]
# この行を消すと`--features ravif`ができるようになる
avif = ["dep:ravif", "dep:rgb"]
またfeaturesセクションでクレートの機能を選択した場合、そのクレートを任意のままにすることはできませんでした。
[dependencies]
chrono = { version = "0.4", optional = true }
serde = { version = "1.0", optional = true }
[features]
# `--features chrono`や`--features chrono,serde`としたときだけchronoに依存したいが、
# `--features serde`でもchronoに依存してしまう
serde = ["dep:serde", "chrono/serde"]
Rust 1.60のCargoで導入された新しい構文chrono?/serdeにより、任意のまま機能を選択できるようになりました。
[dependencies]
chrono = { version = "0.4", optional = true }
serde = { version = "1.0", optional = true }
[features]
# `--features serde`を指定してもchronoは使用されない
# chronoも使用する場合は`--features chrono,serde`とする
serde = ["dep:serde", "chrono?/serde"]
ちなみに依存クレートの関係を可視化するにはcargo treeを使うと便利です。
$ cargo tree --features serde test v0.1.0 (...) └── serde v1.0.136 $ cargo tree --features chrono,serde test v0.1.0 (...) ├── chrono v0.4.19 │ ├── libc v0.2.122 │ ├── num-integer v0.1.44 │ │ └── num-traits v0.2.14 │ │ [build-dependencies] │ │ └── autocfg v1.1.0 │ │ [build-dependencies] │ │ └── autocfg v1.1.0 │ ├── num-traits v0.2.14 (*) │ ├── serde v1.0.136 │ └── time v0.1.43 │ └── libc v0.2.122 └── serde v1.0.136
コード網羅率を計測できるようになった
これまではcargo-tarpaulinやcargo-cov、cargo-kcovなど様々な計測ツールがありましたが、 外から観測する都合上不正確な計測結果になることがありました。
Rust 1.60でソースに基づくコード網羅率(source-based code coverage)が安定化され、コード網羅率をより正確かつ詳細に計測できるようになりました。
この新しい機能を使うにはRUSTFLAGS="-C instrument-coverage" cargo buildとしてビルドした上でバイナリを実行します。
詳細な使い方はこちらの記事を参照してください(記事ではNightlyを使用しているため適宜読み替えてください)。
[u8]を文字列としてエスケープできるようになった
バイト列のスライスに対し、非ASCII文字はエスケープシーケンスで表して文字列化できるようになりました。 デバッグ時などバイナリデータを取り敢えず表示したいという場合に便利です。
fn main() { let data = "あ\r\nabc".as_bytes(); // ASCII部分は文字として、それ以外はエスケープシーケンス付きで表示される println!("{}", data.escape_ascii()); // \xe3\x81\x82\r\nabc }
安定化されたAPIのドキュメント
安定化されたAPIのドキュメントを独自に訳して紹介します。リストだけ見たい方は安定化されたAPIをご覧ください。
Arc::new_cyclic
impl<T> Arc<T> { #[cfg(not(no_global_oom_handling))] #[inline] #[stable(feature = "arc_new_cyclic", since = "1.60.0")] pub fn new_cyclic<F>(data_fn: F) -> Arc<T> where F: FnOnce(&Weak<T>) -> T, { /* 実装は省略 */ } }
生成中のArc<T>への弱参照を使用するクロージャdata_fnを使い、新しいArc<T>を生成する。
一般的に、直接にしろ間接にしろ循環的に自己参照する構造体は、メモリリークを防ぐために強参照を保持するべきではない。
data_fnでは、Tの初期化時に弱参照を複製してTに保持することであとから使用することができる。
Arc<T>::new_cyclicが返るまではArc<T>は完全に生成されないため、
弱参照によるupgradeの呼び出しは失敗し、Noneを返す。
パニック
data_fnがパニックしたとき、そのパニックは呼び出し元に伝播する。
仮のWeak<T>は通常通りドロップする。
サンプル
#![allow(dead_code)] use std::sync::{Arc, Weak}; struct Gadget { me: Weak<Gadget>, } impl Gadget { /// 参照カウント付きでガジェットを生成する。 fn new() -> Arc<Self> { Arc::new_cyclic(|me| Gadget { me: me.clone() }) } /// 自身への参照カウント付きポインタを返す。 fn me(&self) -> Arc<Self> { self.me.upgrade().unwrap() } }
Rc::new_cyclic
impl<T> Rc<T> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "arc_new_cyclic", since = "1.60.0")] pub fn new_cyclic<F>(data_fn: F) -> Rc<T> where F: FnOnce(&Weak<T>) -> T, { /* 実装は省略 */ } }
生成中のRc<T>への弱参照を使用するクロージャdata_fnを使い、新しいRc<T>を生成する。
一般的に、直接にしろ間接にしろ循環的に自己参照する構造体は、メモリリークを防ぐために強参照を保持するべきではない。
data_fnでは、Tの初期化時に弱参照を複製してTに保持することであとから使用することができる。
Rc<T>::new_cyclicが返るまではRc<T>は完全に生成されないため、
弱参照によるupgradeの呼び出しは失敗し、Noneを返す。
パニック
data_fnがパニックしたとき、そのパニックは呼び出し元に伝播する。
仮のWeak<T>は通常通りドロップする。
サンプル
#![allow(dead_code)] use std::rc::{Rc, Weak}; struct Gadget { me: Weak<Gadget>, } impl Gadget { /// 参照カウント付きでガジェットを生成する。 fn new() -> Rc<Self> { Rc::new_cyclic(|me| Gadget { me: me.clone() }) } /// 自身への参照カウント付きポインタを返す。 fn me(&self) -> Rc<Self> { self.me.upgrade().unwrap() } }
slice::EscapeAscii
#[stable(feature = "inherent_ascii_escape", since = "1.60.0")] #[derive(Clone)] #[must_use = "iterators are lazy and do nothing unless consumed"] pub struct EscapeAscii<'a> { /* フィールドは省略 */ }
エスケープされたバイトスライスのイテレーター。
この構造体はslice::escape_asciiで作られる。
詳細はそちらのドキュメントを参照されたい。
<[u8]>::escape_ascii
impl [u8] { #[must_use = "this returns the escaped bytes as an iterator, \ without modifying the original"] #[stable(feature = "inherent_ascii_escape", since = "1.60.0")] pub fn escape_ascii(&self) -> EscapeAscii<'_> { /* 実装は省略 */ } }
このスライスをASCII文字列として扱い、エスケープされた文字を返すイテレーターを返す。
サンプル
let s = b"0\t\r\n'\"\\\x9d"; let escaped = s.escape_ascii().to_string(); assert_eq!(escaped, "0\\t\\r\\n\\'\\\"\\\\\\x9d");
u8::escape_ascii
impl u8 { #[must_use = "this returns the escaped byte as an iterator, \ without modifying the original"] #[stable(feature = "inherent_ascii_escape", since = "1.60.0")] #[inline] pub fn escape_ascii(self) -> ascii::EscapeDefault { /* 実装は省略 */ } }
u8をASCII文字として扱い、エスケープされた文字を返すイテレーターを返す。
ascii::escape_defaultと同一の挙動をする。
サンプル
assert_eq!("0", b'0'.escape_ascii().to_string()); assert_eq!("\\t", b'\t'.escape_ascii().to_string()); assert_eq!("\\r", b'\r'.escape_ascii().to_string()); assert_eq!("\\n", b'\n'.escape_ascii().to_string()); assert_eq!("\\'", b'\''.escape_ascii().to_string()); assert_eq!("\\\"", b'"'.escape_ascii().to_string()); assert_eq!("\\\\", b'\\'.escape_ascii().to_string()); assert_eq!("\\x9d", b'\x9d'.escape_ascii().to_string());
Vec::spare_capacity_mut
impl<T, A: Allocator> Vec<T, A> { #[stable(feature = "vec_spare_capacity", since = "1.60.0")] #[inline] pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<T>] { /* 実装は省略 */ } }
ベクタの余分な容量をMaybeUninit<T>のスライスとして返す。
戻り値のスライスはset_lenメソッドでデータが初期化済みと示す前に、
(ファイルから読み出すなど)ベクタをデータで埋めるのに使用できる。
サンプル
// 10個の要素として十分な大きさのベクタを確保する let mut v = Vec::with_capacity(10); // 最初の3要素を埋める let uninit = v.spare_capacity_mut(); uninit[0].write(0); uninit[1].write(1); uninit[2].write(2); // ベクタの最初の3要素を初期化済みとして示す unsafe { v.set_len(3); } assert_eq!(&v, &[0, 1, 2]);
MaybeUninit::assume_init_drop
impl<T> MaybeUninit<T> { #[stable(feature = "maybe_uninit_extra", since = "1.60.0")] pub unsafe fn assume_init_drop(&mut self) { /* 実装は省略 */ } }
内包する値をその場でドロップする。
MaybeUninitへの所有権がある場合、代替としてassume_initも使える。
安全性
MaybeUninit<T>が本当に初期化状態であることを保証するのは呼び出し側の責任である。
内容が完全に初期化されていない場合にこのメソッドを呼び出すと未定義動作となる。
その上で、型T(またはそのメンバ)のDrop実装が依存する可能性があるため、
Tにおけるすべての更なる不変条件は満たされなければならない。
例えば、Vec<T>に不正だが非NULLアドレスを設定した場合は初期化済みとされる(現在の実装の話であり、安定化された構成要件ではない)ものの、
これはVec<T>でのコンパイラが知る要件はデータポインタが非NULLだけだからである。
そのようなVec<T>をドロップすると未定義動作を引き起こす。
MaybeUninit::assume_init_read
impl<T> MaybeUninit<T> { #[stable(feature = "maybe_uninit_extra", since = "1.60.0")] #[rustc_const_unstable(feature = "const_maybe_uninit_assume_init_read", issue = "63567")] #[inline(always)] #[track_caller] pub const unsafe fn assume_init_read(&self) -> T { /* 実装は省略 */ } }
コンテナMaybeUninit<T>から値を読み取る。戻り値のTは通常通りのドロップ処理が行われる。
可能な限りassume_initの使用が推奨される。
これによりMaybeUninit<T>の内容を複製することを防ぐことができる。
安全性
MaybeUninit<T>が本当に初期化状態であることを保証するのは呼び出し側の責任である。
内容が完全に初期化されていない場合にこのメソッドを呼び出すと未定義動作となる。
この初期化の不変条件については型レベルのドキュメント(※訳注:英語ページ)に詳しい。
さらにはCopyトレイトを実装するかどうかに関わらず、この関数はptr::read関数と同じく内容へのビット単位のコピーを生成する。
(assume_init_readを複数回呼ぶか、assume_init_readのあとにassume_initを呼び出すなど)
データのコピーを複数回使う場合、実際にデータを複製しても良いかの確認は使用者の責任である。
サンプル
このメソッドの正しい使い方
use std::mem::MaybeUninit; let mut x = MaybeUninit::<u32>::uninit(); x.write(13); let x1 = unsafe { x.assume_init_read() }; // `u32`は`Copy`なので複数回readできる let x2 = unsafe { x.assume_init_read() }; assert_eq!(x1, x2); let mut x = MaybeUninit::<Option<Vec<u32>>>::uninit(); x.write(None); let x1 = unsafe { x.assume_init_read() }; // `None`の値を複製するのは構わないので複数回readできる let x2 = unsafe { x.assume_init_read() }; assert_eq!(x1, x2);
このメソッドの間違った使い方
use std::mem::MaybeUninit; let mut x = MaybeUninit::<Option<Vec<u32>>>::uninit(); x.write(Some(vec![0, 1, 2])); let x1 = unsafe { x.assume_init_read() }; let x2 = unsafe { x.assume_init_read() }; // 同一ベクタへの2つのコピーを生成したが、両方ともドロップした場合に二重解放⚠️となる
i{N}::abs_diff
impl i8 { #[stable(feature = "int_abs_diff", since = "1.60.0")] #[rustc_const_stable(feature = "int_abs_diff", since = "1.60.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] pub const fn abs_diff(self, other: Self) -> $UnsignedT { /* 実装は省略 */ } }
selfとotherの絶対差を計算する。
この関数は符号なし整数によって常に正しい答えを返し、オーバーフローすることもパニックすることも無い。
サンプル
基礎的な使い方
assert_eq!(100i8.abs_diff(80), 20u8); assert_eq!(100i8.abs_diff(110), 10u8); assert_eq!((-100i8).abs_diff(80), 180u8); assert_eq!((-100i8).abs_diff(-120), 20u8); assert_eq!(i8::MIN.abs_diff(i8::MAX), u8::MAX);
u{N}::abs_diff
impl u8 { #[stable(feature = "int_abs_diff", since = "1.60.0")] #[rustc_const_stable(feature = "int_abs_diff", since = "1.60.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] pub const fn abs_diff(self, other: Self) -> Self { /* 実装は省略 */ } }
selfとotherの絶対差を計算する。
サンプル
基礎的な使い方
assert_eq!(100u8.abs_diff(80), 20u8); assert_eq!(100u8.abs_diff(110), 10u8);
arch::is_aarch64_feature_detected!
macro_rules! is_aarch64_feature_detected { /* 実装は省略 */ }
AArch64でのみサポートされる。
このマクロはaarch64の機能がaarch64プラットフォーム上で有効化されているかを実行時にテストする。
現在、ほとんどの機能はLinuxベースのプラットフォームでのみサポートされている。
このマクロはテストする機能を表す文字列リテラル1つのみを引数に取る。
機能の名前はほとんどがARM Architecture Reference Manual内のFEAT_*から取られている。
サポートされている引数
"asimd"or "neon" - FEAT_AdvSIMD"pmull"- FEAT_PMULL"fp"- FEAT_FP"fp16"- FEAT_FP16"sve"- FEAT_SVE"crc"- FEAT_CRC"lse"- FEAT_LSE"lse2"- FEAT_LSE2"rdm"- FEAT_RDM"rcpc"- FEAT_LRCPC"rcpc2"- FEAT_LRCPC2"dotprod"- FEAT_DotProd"tme"- FEAT_TME"fhm"- FEAT_FHM"dit"- FEAT_DIT"flagm"- FEAT_FLAGM"ssbs"- FEAT_SSBS"sb"- FEAT_SB"paca"- FEAT_PAuth (address authentication)"pacg"- FEAT_Pauth (generic authentication)"dpb"- FEAT_DPB"dpb2"- FEAT_DPB2"sve2"- FEAT_SVE2"sve2-aes"- FEAT_SVE2_AES"sve2-sm4"- FEAT_SVE2_SM4"sve2-sha3"- FEAT_SVE2_SHA3"sve2-bitperm"- FEAT_SVE2_BitPerm"frintts"- FEAT_FRINTTS"i8mm"- FEAT_I8MM"f32mm"- FEAT_F32MM"f64mm"- FEAT_F64MM"bf16"- FEAT_BF16"rand"- FEAT_RNG"bti"- FEAT_BTI"mte"- FEAT_MTE"jsconv"- FEAT_JSCVT"fcma"- FEAT_FCMA"aes"- FEAT_AES"sha2"- FEAT_SHA1 & FEAT_SHA256"sha3"- FEAT_SHA512 & FEAT_SHA3"sm4"- FEAT_SM3 & FEAT_SM4
変更点リスト
公式リリースノートをベースに意訳・編集・追記をした変更点リストです。
言語
"unwind"と"abort"による#[cfg(panic = "...")]を安定化- 各数値型のサイズ及び
"ptr"において、#[cfg(target_has_atomic = "...")]を安定化
コンパイラ
x86_64-unknown-linux-gnuにおいて+crt-staticとrelocation-model=picの結合を有効化- ネストした、またはグロブによる公開再エクスポートにおいて、リント
unreachable_pubが間違って反応するのを修正 -Z instrument-coverageを-C instrument-coverageとして安定化
→ピックアップ-Z print-link-argsを--print link-argsとして安定化- ターゲット
mips64-openwrt-linux-muslをティア3※に追加した - ターゲット
armv7-unknown-linux-uclibceabiをティア3※に追加した - ドキュメントコメントにおける改行の不正な削除を修正
- RustyHermit向けのカーネルターゲットを追加
- バイナリクレートとライブラリクレートの混在を拒絶するようになった
- rustcがデフォルトで
RUST_BACKTRACE=fullを使うようになった - LLVM 14に更新
※Rustのティア付けされたプラットフォームサポートの詳細はPlatform Supportのページ(英語)を参照
ライブラリ
sort_by_cached_keyの呼び出し順を保証するようになった- 指数と仮数を直接処理することにより、
Duration::try_from_secs_f32/f64の精度を改善した Instant::{duration_since, elapsed, sub}がサチる(飽和する)ようになったInstant::nowにおける、単調増加しない時計向けワークアラウンドを削除したBuildHasherDefaultとiter::Empty、future::Pendingを共変とした
安定化されたAPI
※各APIのドキュメントを独自に訳した安定化されたAPIのドキュメントもご参照ください。
Arc::new_cyclicRc::new_cyclicslice::EscapeAscii<[u8]>::escape_asciiu8::escape_asciiVec::spare_capacity_mutMaybeUninit::assume_init_dropMaybeUninit::assume_init_readi8::abs_diffi16::abs_diffi32::abs_diffi64::abs_diffi128::abs_diffisize::abs_diffu8::abs_diffu16::abs_diffu32::abs_diffu64::abs_diffu128::abs_diffusize::abs_diffDisplay for io::ErrorKindFrom<u8> for ExitCodeNot for !(the "never" type)- Op
Assign<$t> for Wrapping<$t> arch::is_aarch64_feature_detected!
その他
- 類似したティア1プラットフォームのドキュメントを再利用してティア2プラットフォームのドキュメントを配信するようになった
- 完全プロファイルからrustcのドキュメントを排除した
- bootstrap:llvmのビルド向けにフラグ処理を整理した
Cargo
- cargoを
toml-rsからtoml_editに移植した -Ztimingsを--timingsとして安定化した
→ピックアップ- 名前空間付き機能(features)及び弱依存機能を安定化
→ピックアップ - ビルドスクリプト(※訳注:
build.rsなど)から、更にcargo:rustc-link-arg-*を受け入れるようになった - サブディレクトリ内での
cargo-newがCargo.lockを無視ルールに追加しないようになった
互換性メモ
- Androidにおいて、コンパイラーランタイムのリンク時ハックを削除した
Instant::nowでの時計が単調増加しないプラットフォーム向け緩和策が削除された。 単調増加する時計を提供しないプラットフォームにおいては、 後から取得したInstantが以前に取得したInstantよりも大きくなる保証がなくなったInstant::{duration_since, elapsed, sub}がアンダーフロー時にパニックしなくなり、代わりに0で飽和するようになった。 実際にパニックが発生するのは単調増加する時計の実装にバグがあるプラットフォームがほとんどで、 開始時刻と終了時刻を逆にするようなプログラミングのミスを捉えることはできなかった。 こういったミスにおいては、パニックする代わりに結果が0になるようになった- 将来のリリースにおいて、最低ラインの要求を、Linuxカーネルはバージョン3.2に、glibcは2.17に引き上げることを予定している。 PR #95026にてぜひフィードバックを!
内部の変更
これらの変更は直接ユーザーの利益に繋がるものではないが、rustc及び関連ツールにおける内部の改善や全体的なパフォーマンスの改善をもたらす。
関連リンク
さいごに
次のRust 1.61は2022/5/19(金)に予定されています。
std::io::stdin()を変数に入れなくてもlock()できるようになるようです。
オプティムでは解脱を目指すエンジニアを募集しています。
ライセンス表記
- この記事はApache 2/MITのデュアルライセンスで公開されている公式リリースノート及びドキュメントから翻訳・追記をしています
- 冒頭の画像中にはRust公式サイトで配布されているロゴを使用しており、 このロゴはMozillaまたはRust財団によってCC-BYの下で配布されています
- 冒頭の画像はいらすとやさんの画像を使っています。いつもありがとうございます
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Apache License
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.