Warning
This package is under construction, handle with care!
attrimpl
The aim of the package is to reduce boilerplate code by adding implementations in trivial cases.
Directives
Directives that can be added before fields
from: implementsFromtrait for the given typeinto: implementsIntotrait for the given typeconvert: add bothfromandintodirectives for the given field
Upcoming implementations:
- Traits
IntoFromDerefDerefMutAsrefAsMut
- Getter methods
Examples
Named struct:
// non-boxed
let mut value = from;
value.push_str;
let value: String = value.into;
// boxed
let mut value = Box::from;
value.push_str;
let value: String = .into;
Tuple struct:
] String);
// non-boxed
let mut value = from;
value.push_str;
let value: String = value.into;
// boxed
let mut value = Box::from;
value.push_str;
let value: String = .into;
Enum:
// non-boxed
let value = from;
// boxed
let value = Box::from;
Todo
- handle errors in the package instead of relying on the Rust compiler where possible
- examine whether it is possible to implement deref, deref_mut, into, as_ref, as_mut on enums if every variant contains the same type
#[attrimpl(from)]should work with multiple field structs and enums. Should be able to set the default values of the other fields (e.g.,#[attrimpl(from(field_default | container_default))]).- write test framework for compile time errors
- write a failing test where non-defined directive is given
- implement the following directives
#[attrimpl(convert)]#[attrimpl(from)]#[attrimpl(into)]
#[attrimpl(deref_both)]#[attrimpl(deref)]#[attrimpl(deref_mut)]
#[access(copy | clone | ref)]#[attrimpl(get_ref)]#[attrimpl(get_mut)]#[attrimpl(get_copy)]#[attrimpl(get_clone)]
#[attrimpl(as)]#[attrimpl(as_ref)]#[attrimpl(as_mut)]
#[attrimpl(display("asdasd {}"))]- not sure whether to implement that one: #[attrimpl(borrow)]
- search for othe possibilities of useful directives