#[test]
fn named_struct_convert() {
#[attrimpl::attrimpl]
struct NamedStruct {
#[attrimpl(from, into)]
name: String,
}
let value = Box::<NamedStruct>::from("test".to_string());
assert_eq!(value.name, "test");
let value: String = (*value).into();
assert_eq!(value, "test");
}
#[test]
fn named_struct_complex() {
#[attrimpl::attrimpl]
struct NamedStruct {
#[attrimpl(into)]
#[attrimpl(as_ref, as_mut)]
#[attrimpl(get_ref)]
name: String,
#[attrimpl(deref_mut)]
#[attrimpl(get)]
hobby: String,
}
let mut value = NamedStruct {
name: "Jane Doe".to_string(),
hobby: "rock climbing".to_string(),
};
*value = "ice climbing".to_string();
assert_eq!(*value, "ice climbing");
*value.hobby_mut() = "rock climbing".to_string();
assert_eq!(value.hobby(), "rock climbing");
assert_eq!(value.name(), "Jane Doe");
assert_eq!(value.as_ref(), "Jane Doe");
*value.as_mut() = "John Doe".to_string();
assert_eq!(value.as_ref(), "John Doe");
let value: String = value.into();
assert_eq!(value, "John Doe");
}