Skip to content

Commit

Permalink
rename lib name
Browse files Browse the repository at this point in the history
  • Loading branch information
duke-git committed Apr 16, 2024
1 parent 62c8746 commit 0ee3a32
Show file tree
Hide file tree
Showing 120 changed files with 153 additions and 150 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "ruf"
name = "rufl"
version = "0.1.1"
authors = ["[email protected]"]
edition = "2021"
description = "A powerful util function library for rust"
license = "MIT"
repository = "https://github.com/duke-git/ruf"
repository = "https://github.com/duke-git/rufl"
keywords = ["rust", "util", "lib", "function", "common"]
categories = ["utils"]

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<br/>
</div>

#### Ruf is an util function library for rust. It provides a series of useful functions to make your rust development easier.
#### Rufl is an util function library for rust. It provides a series of useful functions to make your rust development easier.

_Ruf is short for "rust util function"._
_Ruf is short for "rust util function library"._

## [简体中文](./README_zh-CN.md)

Expand All @@ -25,11 +25,11 @@ ruf = "0.1.1"

## Example

Here takes the string function `add_commas` (Add comma to a number value by every 3 numbers from right. Ahead by prefix symbol.) as an example, and the `ruf::string` mod needs to be used.
Here takes the string function `add_commas` (Add comma to a number value by every 3 numbers from right. Ahead by prefix symbol.) as an example, and the `rufl::string` mod needs to be used.

Code:
```rust
use ruf::string;
use rufl::string;

fn main() {
let money_amount: String = string::add_commas("1234567", "$");
Expand Down
6 changes: 3 additions & 3 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<br/>
</div>

#### Ruf是一个Rust语言工具函数库。它提供了许多工具函数,让你的rust开发变得更简单.
#### Rufl是一个Rust语言工具函数库。它提供了许多工具函数,让你的rust开发变得更简单.

_Ruf是”rust util function"的缩写。_

Expand All @@ -25,11 +25,11 @@ ruf = "0.1.1"

## 示例

这里以字符串函数`add_commas`为例,该函数的作用是每隔3位数(从右边开始)向数字值中添加逗号,并在前面添加前缀符号。为了实现这个功能,我们需要用到 `ruf::string`模块。
这里以字符串函数`add_commas`为例,该函数的作用是每隔3位数(从右边开始)向数字值中添加逗号,并在前面添加前缀符号。为了实现这个功能,我们需要用到 `rufl::string`模块。

代码:
```rust
use ruf::string;
use rufl::string;

fn main() {
let money_amount: String = string::add_commas("1234567", "$");
Expand Down
2 changes: 1 addition & 1 deletion src/collection/all_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(true, collection::all_match(&[1, 2, 3], &|n: &i32, _i: usize| *n <= 3));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(vec![vec![1, 2], vec![3, 4], vec![5]], collection::chunk(vec![1, 2, 3, 4, 5], 2));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(1, collection::count(&[1, 2, 3], 1));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/count_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(2, collection::count_by([1, 2, 3, 4, 5], &|n: &i32, _i: usize| *n < 3));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/difference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(vec![1], collection::difference([1, 2], [2, 3]));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/difference_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(vec![1.2], collection::difference_by([1.2, 2.1], [2.3, 3.4], &|n: &f64, _i: usize| {n.floor()}));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/difference_with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(vec![1, 5], collection::difference_with(vec![1, 2, 3, 4, 5], vec![4, 5, 6, 7, 8], &|n1: i32, n2: i32| { n2 == n1 * 2}));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// let vec1 = vec![0; 5];
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!([1, 2, 3].to_vec(), collection::filter(&[1, 2, 3, 4, 5].to_vec(), &|n: &i32, _i: usize| *n <= 3));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/filter_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(
/// [4, 8].to_vec(),
Expand Down
2 changes: 1 addition & 1 deletion src/collection/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(Some((4, 3)), collection::find([1, 2, 3, 4, 5], &|n: &i32, _i: usize| *n > 3, 0));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/find_last.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(Some((4, 3)), collection::find_last([1, 2, 3, 4, 5], &|n: &i32, _i: usize| *n > 3, 3));
///
Expand Down
8 changes: 4 additions & 4 deletions src/collection/index_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(None, collection::index_of(&[1, 2, 3], &0));
///
/// assert_eq!(Some(1), collection::index_of(&[1, 2, 3, 2], &2));
///
///
/// ```

pub fn index_of<C: AsRef<[T]>, T: PartialEq+Clone>(collection: &C, item: &T) -> Option<usize> {
pub fn index_of<C: AsRef<[T]>, T: PartialEq + Clone>(collection: &C, item: &T) -> Option<usize> {
for (i, v) in collection.as_ref().to_vec().iter().enumerate() {
if *v == *item {
return Some(i)
return Some(i);
}
}

Expand Down
21 changes: 12 additions & 9 deletions src/collection/insert_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// * `vec` - The vector to insert.
///
/// * `index` - The position of vector to insert at.
///
///
/// * `item` - The element to be inserted.
///
/// # Returns
Expand All @@ -16,23 +16,23 @@
/// # Examples
///
/// ```
/// use ruf::collection;
///
/// use rufl::collection;
///
/// let mut vec = vec!["a", "b", "c"];
///
///
/// let result = collection::insert_at(&mut vec, 3, "d");
///
///
/// assert_eq!(true, result.ok().unwrap());
/// assert_eq!(vec!["a", "b", "c", "d"], vec);
///
///
/// ```

pub fn insert_at<T>(vec: &mut Vec<T>, index: usize, item: T) -> Result<bool, String> {
if index > vec.len() {
return Err(String::from("insert_at: index should be <= vecor length"));
}

vec.insert(index, item);
vec.insert(index, item);

Ok(true)
}
Expand All @@ -44,7 +44,7 @@ mod tests {
#[test]
fn test_insert_at() {
let mut vec = vec![];

let result = insert_at(&mut vec, 0, "a");
assert_eq!(true, result.ok().unwrap());
assert_eq!(vec!["a"], vec);
Expand All @@ -54,7 +54,10 @@ mod tests {
assert_eq!(vec!["a", "b"], vec);

let result = insert_at(&mut vec, 3, "c");
assert_eq!("insert_at: index should be <= vecor length", result.err().unwrap());
assert_eq!(
"insert_at: index should be <= vecor length",
result.err().unwrap()
);
assert_eq!(vec!["a", "b"], vec);
}
}
2 changes: 1 addition & 1 deletion src/collection/intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(vec![2, 3], collection::intersection(vec![vec![1, 2, 2, 3], vec![2, 3, 4]]));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/is_ascending_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(true, collection::is_ascending_order(&[1, 2, 3]));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/is_descending_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(false, collection::is_descending_order(&[1, 2, 3]));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/is_sorted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(true, collection::is_sorted(&[1, 2, 3]));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/last_index_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(None, collection::last_index_of(&[1, 2, 3], &0));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(vec![2, 3, 4, 5, 6], collection::map(&vec![1, 2, 3, 4, 5], &|n: &i32, _i: usize| { *n + 1 }));
///
Expand Down
6 changes: 3 additions & 3 deletions src/collection/max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(Some(3), collection::max(&vec![1, 2, 3, 2]));
///
Expand All @@ -23,7 +23,7 @@
/// ```

pub fn max<C: AsRef<[T]>, T: PartialOrd + Clone>(collection: &C) -> Option<T> {
let vector = collection.as_ref().to_vec();
let vector = collection.as_ref().to_vec();

match vector.len() {
0 => None,
Expand All @@ -38,7 +38,7 @@ pub fn max<C: AsRef<[T]>, T: PartialOrd + Clone>(collection: &C) -> Option<T> {
// max = cmp::max(max, vector[i])
}

return Some(max.clone())
return Some(max.clone());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/collection/min.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(Some(1), collection::min(&vec![1, 2, 3, 2]));
///
Expand All @@ -23,7 +23,7 @@
/// ```

pub fn min<C: AsRef<[T]>, T: PartialOrd + Clone>(collection: &C) -> Option<T> {
let vector = collection.as_ref().to_vec();
let vector = collection.as_ref().to_vec();

match vector.len() {
0 => None,
Expand All @@ -37,7 +37,7 @@ pub fn min<C: AsRef<[T]>, T: PartialOrd + Clone>(collection: &C) -> Option<T> {
}
}

return Some(min.clone())
return Some(min.clone());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/collection/none_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(true, collection::none_match(&[1, 2, 3], &|n: &i32, _i: usize| *n > 3));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!((vec![2, 4], vec![1, 3, 5]), collection::partition(&vec![1, 2, 3, 4, 5], |n: &i32, _i: usize| n % 2 == 0));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(15, collection::reduce(&vec![1, 2, 3, 4, 5], |x: &i32, y: &i32, i: usize| { x + y }, 0));
///
Expand Down
2 changes: 1 addition & 1 deletion src/collection/reduce_right.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// # Examples
///
/// ```
/// use ruf::collection;
/// use rufl::collection;
///
/// assert_eq!(9, collection::reduce_right(&vec!["hello", "rust"], |agg, item, _: usize| { agg + item.len() }, 0));
///
Expand Down
Loading

0 comments on commit 0ee3a32

Please sign in to comment.