You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I just started using this crate and looks quite promising!
I want to check if there is some limitation with the crate or maybe I'm doing something wrong.
Here is what I found in my tests:
Enum to enum, works.
Struct without enum, works.
Struct with enum, do not work.
Is the correct? Is it possible to convert a complex struct with enum fields?
Here is a minimal example.
I have a BaseStruct with an BaseEnum field, all of them derive from LabelledGeneric, and I want to convert to a TargetStruct with a TargetEnum field. All of the them have the same names and member order.
extern crate frunk;
extern crate frunk_core;
use frunk::{labelled::Transmogrifier, LabelledGeneric};
fn main() {
// works
let target: TargetEnum = frunk::labelled_convert_from(BaseEnum::default());
// works
let target: TargetStruct = frunk::labelled_convert_from(BaseStruct::default());
let target: TargetStruct = frunk::transform_from(BaseStruct::default());
let target: TargetStruct = BaseStruct::default().transmogrify();
// Doesn't work
let target: TargetStruct = frunk::from_labelled_generic(BaseStruct::default());
// No conversion works for the "complex" struct
let target: TargetComplexStruct = frunk::labelled_convert_from(BaseComplexStruct::default());
let target: TargetComplexStruct = frunk::from_labelled_generic(BaseComplexStruct::default());
let target: TargetComplexStruct = frunk::transform_from(BaseComplexStruct::default());
let target: TargetComplexStruct = BaseComplexStruct::default().transmogrify();
}
#[derive(Clone, PartialEq, Eq, Hash, Debug, LabelledGeneric)]
enum BaseEnum {
SomeValue,
}
impl Default for BaseEnum {
fn default() -> Self {
BaseEnum::SomeValue
}
}
#[derive(Clone, PartialEq, Eq, Hash, Debug, LabelledGeneric)]
enum TargetEnum {
SomeValue,
}
#[derive(Default, Clone, PartialEq, Eq, Hash, Debug, LabelledGeneric)]
struct BaseStruct {
test: String,
}
#[derive(Clone, PartialEq, Eq, Hash, Debug, LabelledGeneric)]
struct TargetStruct {
test: String,
}
#[derive(Default, Clone, PartialEq, Eq, Hash, Debug, LabelledGeneric)]
struct BaseComplexStruct {
test: String,
other: BaseEnum,
}
#[derive(Clone, PartialEq, Eq, Hash, Debug, LabelledGeneric)]
struct TargetComplexStruct {
test: String,
other: TargetEnum,
}
The text was updated successfully, but these errors were encountered:
Hi, I just started using this crate and looks quite promising!
I want to check if there is some limitation with the crate or maybe I'm doing something wrong.
Here is what I found in my tests:
Is the correct? Is it possible to convert a complex struct with enum fields?
Here is a minimal example.
I have a BaseStruct with an BaseEnum field, all of them derive from LabelledGeneric, and I want to convert to a TargetStruct with a TargetEnum field. All of the them have the same names and member order.
The text was updated successfully, but these errors were encountered: