Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoikey committed Sep 16, 2024
1 parent f6e399d commit 3ab0ecb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 35 deletions.
31 changes: 6 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
**refined-type** is a library developed for Rust. It enhances your types, making them more robust and expanding the
range of guarantees your applications can statically ensure.

# Installation

```shell
cargo add refined_type
```

# Overview

You can create various rules for a certain type, such as phone numbers, addresses, times, and so on.
Expand Down Expand Up @@ -70,31 +76,6 @@ fn example_3() -> anyhow::Result<()> {
}
```

# Installation

```shell
cargo add refined_type
```

# Custom Rule

There are many situations where you may want to define custom rules.
To define rules for a specific target type, you first need to define a struct.
In the struct, define fields for specifying detailed conditions.
Once the definition is complete, all you need to do is implement the Rule trait.
Add your preferred conditions as you like.

```rust
fn example_4() -> anyhow::Result<()> {
let non_empty_string_result = Refined::<NonEmptyStringRule>::new("Hello World".to_string())?;
assert_eq!(non_empty_string_result.into_value(), "Hello World");

let empty_string_result = Refined::<NonEmptyStringRule>::new("".to_string());
assert!(empty_string_result.is_err());
Ok(())
}
```

# Compose Rules

As mentioned earlier, it is possible to combine any rules as long as the target types match.
Expand Down
10 changes: 0 additions & 10 deletions tests/read_me.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,6 @@ fn example_3() -> anyhow::Result<()> {
Ok(())
}

#[test]
fn example_4() -> anyhow::Result<()> {
let non_empty_string_result = Refined::<NonEmptyStringRule>::new("Hello World".to_string())?;
assert_eq!(non_empty_string_result.into_value(), "Hello World");

let empty_string_result = Refined::<NonEmptyStringRule>::new("".to_string());
assert!(empty_string_result.is_err());
Ok(())
}

struct ContainsHelloRule;
struct ContainsCommaRule;
struct ContainsWorldRule;
Expand Down

0 comments on commit 3ab0ecb

Please sign in to comment.