# PartialThis
[](https://github.com/2A5F/partial_this/actions/workflows/rust.yml)
[](https://github.com/2A5F/partial_this/actions/workflows/miri.yml)
[](https://github.com/2A5F/partial_this/actions/workflows/clippy.yml)
[](https://crates.io/crates/partial_this)
[](https://docs.rs/partial_this)

Type-safe partial construction
```rust
#[partial]
#[derive(Debug)]
pub struct Foo {
pub foo: i32,
pub bar: f32,
}
fn test() {
let p = Foo::partial(Box::new_uninit());
let p = p.with_foo(1);
let p = p.with_bar(1.0);
let foo: Box<Foo> = p.done();
println!("{:?}", foo);
}
```
- Multi partial overloads.
```rust
let foo: Box<Foo> = Foo::partial(Box::new_uninit()).done();
let foo: Foo = Foo::partial(MaybeUninit::uninit()).done();
let mut foo = MaybeUninit::uninit();
let foo: &mut Foo = Foo::partial(&mut foo).done();
```
- Field initialization methods. Can be called in any order and at most once.
```rust
let p = p.with_foo(1);
let p = p.with_bar(1.0);
```
```rust
let p = p.with_bar(1.0);
let p = p.with_foo(1);
```
```rust
let p = p.with_foo(1);
let p = p.with_foo(1); ```
- Field access methods. Can be called after initialization.
```rust
let p = p.with_foo(1);
println!("{}", p.get_foo());
```
```rust
let mut p = p.with_foo(1);
p.set_foo(123);
```
- Done method.Can be called after all fields are initialized.
```rust
let foo = p.done();
```
- Drop safe. Will call fields `drop` according to the field initialization status and in the reverse order of initialization (the last field initialized is dropped first).
```rust
struct Some {
field0: ...,
field1: ...,
field2: ...,
...
}
let p = Some::partial(Box::new_uninit());
let p = p.field0(...);
let p = p.field1(...);
drop(p); ```