<commit_before>// Copyright 2015 <NAME>
//
// 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.

//! Temporary traits for function operator overloading, pending the stabilization of `Fn`, `FnMut`,
//! and `FnOnce`.
//!
//! ```rust
//! use fn_ops::*;
//!
//! struct IsMultipleOf(i32);
//!
//! impl FnOnce<(i32, i32)> for IsMultipleOf {
//!     type Output = bool;
//!
//!     fn call_once(self, (x, y): (i32, i32)) -> bool { self.call((x, y)) }
//! }
//!
//! impl FnMut<(i32, i32)> for IsMultipleOf {
//!     fn call_mut(&mut self, (x, y): (i32, i32)) -> bool { self.call((x, y)) }
//! }
//!
//! impl Fn<(i32, i32)> for IsMultipleOf {
//!     fn call(&self, (x, y): (i32, i32)) -> bool {
//!         x * self.0 == y
//!     }
//! }
//!
//! fn assert_fn<Args, F: Fn<Args, Output = bool>>(args: Args, f: F) {
//!     assert!(f.call(args))
//! }
//!
//! assert_fn((1, 2), IsMultipleOf(2));
//! assert_fn((1, 2, 3), |x, y, z| x != y && y != z && z != x);
//! ```

use std::ops;


pub trait FnOnce<Args> {
    type Output;
    fn call_once(self, args: Args) -> Self::Output;
}

pub trait FnMut<Args>: FnOnce<Args> {
    fn call_mut(&mut self, args: Args) -> Self::Output;
}

pub trait Fn<Args>: FnMut<Args> {
    fn call(&self, args: Args) -> Self::Output;
}<commit_msg>Documentation improvements<commit_after>// Copyright 2015 <NAME>
//
// 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.

//! Temporary traits for function operator overloading, pending the stabilization of `Fn`, `FnMut`,
//! and `FnOnce`.
//!
//! # Example
//!
//! ```rust
//! use fn_ops::*;
//!
//! struct IsMultipleOf(i32);
//!
//! impl FnOnce<(i32, i32)> for IsMultipleOf {
//!     type Output = bool;
//!
//!     fn call_once(self, (x, y): (i32, i32)) -> bool { self.call((x, y)) }
//! }
//!
//! impl FnMut<(i32, i32)> for IsMultipleOf {
//!     fn call_mut(&mut self, (x, y): (i32, i32)) -> bool { self.call((x, y)) }
//! }
//!
//! impl Fn<(i32, i32)> for IsMultipleOf {
//!     fn call(&self, (x, y): (i32, i32)) -> bool {
//!         x * self.0 == y
//!     }
//! }
//!
//! fn assert_fn<Args, F: Fn<Args, Output = bool>>(args: Args, f: F) {
//!     assert!(f.call(args))
//! }
//!
//! assert_fn((1, 2), IsMultipleOf(2));
//! assert_fn((1, 2, 3), |x, y, z| x != y && y != z && z != x);
//! ```

use std::ops;


/// A version of the call operator that takes a by-value receiver.
///
/// This is implemented for:
///
/// - `std::ops::FnOnce() -> Output`
/// - `std::ops::FnOnce(a: A) -> Output`
/// - `std::ops::FnOnce(a: A, b: B) -> Output`
/// - `std::ops::FnOnce(a: A, b: B, c: C) -> Output`
/// - `std::ops::FnOnce(a: A, b: B, c: C, d: D) -> Output`
/// - `std::ops::FnOnce(a: A, b: B, c: C, d: D, e: E) -> Output`
pub trait FnOnce<Args> {
    type Output;
    fn call_once(self, args: Args) -> Self::Output;
}

/// A version of the call operator that takes a mutable receiver.
///
/// This is implemented for:
///
/// - `std::ops::Fn() -> Output`
/// - `std::ops::Fn(a: A) -> Output`
/// - `std::ops::Fn(a: A, b: B) -> Output`
/// - `std::ops::Fn(a: A, b: B, c: C) -> Output`
/// - `std::ops::Fn(a: A, b: B, c: C, d: D) -> Output`
/// - `std::ops::Fn(a: A, b: B, c: C, d: D, e: E) -> Output`
pub trait FnMut<Args>: FnOnce<Args> {
    fn call_mut(&mut self, args: Args) -> Self::Output;
}

/// A version of the call operator that takes an immutable receiver.
///
/// This is implemented for:
///
/// - `std::ops::Fn() -> Output`
/// - `std::ops::Fn(a: A) -> Output`
/// - `std::ops::Fn(a: A, b: B) -> Output`
/// - `std::ops::Fn(a: A, b: B, c: C) -> Output`
/// - `std::ops::Fn(a: A, b: B, c: C, d: D) -> Output`
/// - `std::ops::Fn(a: A, b: B, c: C, d: D, e: E) -> Output`
pub trait Fn<Args>: FnMut<Args> {
    fn call(&self, args: Args) -> Self::Output;
}
{'fraction_non_alphanumeric': 0.23046049852133502, 'fraction_numerical': 0.017321504013519222, 'mean_word_length': 2.7460443037974684, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1239464', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1720, 'n_words': 566}