Skip to content

Commit

Permalink
Update README.md (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasterV authored Jan 27, 2025
1 parent 5c8a0a1 commit 64a4e1b
Showing 1 changed file with 0 additions and 36 deletions.
36 changes: 0 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,42 +47,6 @@ fn test_generic_type(ctx: &mut MyGenericContext<u32>) {
}
```

with generic types, you can use same type with different values

```rust
use test_context::{test_context, TestContext};
use std::marker::PhantomData;

struct MyGenericContext<T> {
value: u32,
_marker: PhantomData<T>,
}

impl TestContext for MyGenericContext<String> {
fn setup() -> MyGenericContext<String> {
MyGenericContext { value: 1, _marker: PhantomData }
}
}

#[test_context(MyGenericContext<String>)]
#[test]
fn test_generic_type(ctx: &mut MyGenericContext<String>) {
assert_eq!(ctx.value, 1);
}

impl TestContext for MyGenericContext<u32> {
fn setup() -> MyGenericContext<u32> {
MyGenericContext { value: 2, _marker: PhantomData }
}
}

#[test_context(MyGenericContext<u32>)]
#[test]
fn test_generic_type_u32(ctx: &mut MyGenericContext<u32>) {
assert_eq!(ctx.value, 2);
}
```

Alternatively, you can use `async` functions in your test context by using the
`AsyncTestContext`.

Expand Down

0 comments on commit 64a4e1b

Please sign in to comment.