-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(schema)!: prepend module to declarations in BorshSchema
#300
Conversation
BorshSchema
BorshSchema
BorshSchema
BorshSchema
… of `BorshSchema` for enums
similarly #[derive(BorshSchema)]
enum A {
Bacon(Vec<i64>),
Eggs,
} from schema_full_path_crate {
"Vec<i64>": Sequence {
length_width: 4,
length_range: 0..=4294967295,
elements: "i64",
},
"i64": Primitive(
8,
),
"schema_full_path_crate::A": Enum {
tag_width: 1,
variants: [
(
0,
"Bacon",
"schema_full_path_crate::___ABacon",
),
(
1,
"Eggs",
"schema_full_path_crate::___AEggs",
),
],
},
"schema_full_path_crate::___ABacon": Struct {
fields: UnnamedFields(
[
"Vec<i64>",
],
),
},
"schema_full_path_crate::___AEggs": Struct {
fields: Empty,
},
} |
and then, use schema_full_path_crate::A as AForeign;
#[derive(BorshSchema)]
struct B {
x: A,
y: AForeign,
} from sample_schema_two_crates BorshSchemaContainer {
declaration: "sample_schema_two_crates::B",
definitions: {
"Vec<i64>": Sequence {
length_width: 4,
length_range: 0..=4294967295,
elements: "i64",
},
"i64": Primitive(
8,
),
"sample_schema_two_crates::A": Enum {
tag_width: 1,
variants: [
(
0,
"UnitVariant",
"sample_schema_two_crates::___AUnitVariant",
),
],
},
"sample_schema_two_crates::B": Struct {
fields: NamedFields(
[
(
"x",
"sample_schema_two_crates::A",
),
(
"y",
"schema_full_path_crate::A",
),
],
),
},
"sample_schema_two_crates::___AUnitVariant": Struct {
fields: Empty,
},
"schema_full_path_crate::A": Enum {
tag_width: 1,
variants: [
(
0,
"Bacon",
"schema_full_path_crate::___ABacon",
),
(
1,
"Eggs",
"schema_full_path_crate::___AEggs",
),
],
},
"schema_full_path_crate::___ABacon": Struct {
fields: UnnamedFields(
[
"Vec<i64>",
],
),
},
"schema_full_path_crate::___AEggs": Struct {
fields: Empty,
},
},
} |
Seems only this solution will work with 3rd party crates. In my crate I have solutions to rename or use type alias, so not a problem. Question,
|
Yes. But if the types use semantically identical types from their respective crates as their fields, then they will technically
The triple underscore prefix ( But then, crate+mod prefix leaks implementation detail outside as well, so this pr most likely won't be merged.
It's the same type |
@dzmitry-lahoda , also, conflict detection of names as of now cannot be made perfect, at least because recursive types were allowed, so someone can accidentally or in an intentfull way replace or "shadow" someone else's declaration, if many crates are involved and very complex schemas are constructed. |
sketch of possible solution to #92, both the original issue and the widened perspective
this results in
=>
this may have very weak interoperability with borsh-js due to being specific to rust