Skip to content

Commit

Permalink
2. [release:1.1.0]
Browse files Browse the repository at this point in the history
  • Loading branch information
just-do-halee committed Dec 19, 2021
1 parent ee071db commit 9728c71
Show file tree
Hide file tree
Showing 14 changed files with 683 additions and 251 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.1.0 (December 19, 2021)

### Release 1.1.0
* New Features:
- *Cursor::new_with_extras::<`Extras`>(*`slice`*);*
- *StrCursor::new_with_extras::<`Extras`>(*`str`*);*

---

## 1.0.0 (December 19, 2021)

### Release 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cursor"
version = "1.0.0"
version = "1.1.0"
authors = ["just-do-halee <[email protected]>"]
homepage = "https://github.com/just-do-halee/cursor"
repository = "https://github.com/just-do-halee/cursor"
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ A more free Rust-Iterator.
[twitter-url]: https://twitter.com/do_halee
[crates-url]: https://crates.io/crates/cursor
[license-url]: https://github.com/just-do-halee/cursor
| [Examples](https://github.com/just-do-halee/cursor/tree/main/examples) | [Docs](https://docs.rs/cursor) | [Latest Note](https://github.com/just-do-halee/cursor/blob/main/CHANGELOG.md) |
| [Examples](./examples) | [Docs](https://docs.rs/cursor) | [Latest Note](./CHANGELOG.md) |

```toml
[dependencies]
cursor = "1.0.0"
cursor = "1.1.0"
```

---

# [Example](https://github.com/just-do-halee/cursor/tree/main/examples)
# [Example](./examples)

```rust
use cursor::*;
Expand Down Expand Up @@ -57,4 +57,6 @@ fn example9() {
assert_eq!(cursor.as_remaining_str(), "다. ^^");

}
```
```

#### *Please check the [examples folder](./examples) for detailed features. There are more than you can imagine.*
140 changes: 140 additions & 0 deletions examples/advanced.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#![allow(clippy::while_let_on_iterator)]

use cursor::*;

const SLICE: &[u8] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const STRING: &str = "this is test. 안녕하세요. 이것은 #&*@( 테스트입니다. ^^ thanks.";

#[derive(Debug)]
struct Counter(pub usize);

impl Counter {
pub fn _new() -> Self {
Counter(0)
}
fn _clone(&self) -> Self {
Counter(self.0)
}
fn _reset(&mut self) {
self.0 = 0;
}
}

impl Extras<u8> for Counter {
fn new() -> Self {
Counter::_new()
}
fn clone(&self) -> Self {
self._clone()
}
fn reset(&mut self) {
self._reset()
}
fn change(&mut self, input: &u8) {
if input % 2 == 0 {
self.0 += 1;
}
}
}

impl Extras<char> for Counter {
fn new() -> Self {
Counter::_new()
}
fn clone(&self) -> Self {
self._clone()
}
fn reset(&mut self) {
self._reset()
}
fn change(&mut self, input: &char) {
if *input == ' ' {
self.0 += 1;
}
}
}

fn main() {
example1();
example2();
example3();
example4();
println!();
}

#[inline]
fn example1() {
// even counter
let mut cursor = Cursor::new_with_extras::<Counter>(SLICE);

cursor.next_to_last();

let extra = cursor.into_extras();

assert_eq!(extra.0, 5);
println!("{:?}", extra);
}

#[inline]
fn example2() {
// space counter
let mut cursor = StrCursor::new_with_extras::<Counter>(STRING);

cursor.next_to_last();

let extra = cursor.into_extras();

assert_eq!(extra.0, 8);
println!("{:?}", extra);
}

#[inline]
fn example3() {
let mut cursor = StrCursor::new(STRING);
cursor += 4;
assert_eq!(cursor.current(), ' ');

while let Some(ch) = &mut cursor + 1 {
if let Some(next) = match ch {
' ' => &mut cursor + 1,
'.' => &mut cursor + 2,
_ => None,
} {
print!("{}", next);
}
}
}

#[inline]
fn example4() {
let mut cursor = StrCursor::new(STRING);
cursor.save();
assert_eq!(cursor.saved_pos(), 0);

cursor += 4;
assert_eq!(cursor.current(), ' ');

assert_eq!(cursor.load_str(), "this ");

cursor.save();
assert_eq!(cursor.saved_pos(), 4);

cursor -= 2;
assert_eq!(cursor.current(), 'i');

assert_eq!(cursor.load_str(), "is ");

let mut cursor = StrCursor::new("한글테스트^^");
cursor.save();
assert_eq!(cursor.saved_pos(), 0);

cursor += 4;
assert_eq!(cursor.current(), '트');

assert_eq!(cursor.load_str(), "한글테스트");

cursor.save();
cursor -= 2;

assert_eq!(cursor.load_str(), "테스트");
}
1 change: 1 addition & 0 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fn main() {
example7();
example8();
example9();
println!();
}

#[inline]
Expand Down
3 changes: 1 addition & 2 deletions examples/str_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fn main() {
example7();
example8();
example9();
println!();
}

#[inline]
Expand Down Expand Up @@ -42,7 +43,6 @@ fn example3() {
#[inline]
fn example4() {
let mut cursor = StrCursor::new("test ascii only!");

for _ in cursor.raw_range() {
cursor += 1;
print!("{} ", cursor.current());
Expand All @@ -52,7 +52,6 @@ fn example4() {
#[inline]
fn example5() {
let mut cursor = StrCursor::new("test ascii only!");

for _ in cursor.raw_range() {
let i = &mut cursor + 1;
print!("{} ", i.unwrap());
Expand Down
Loading

0 comments on commit 9728c71

Please sign in to comment.