Skip to content
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 #306

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion borsh-derive/src/internals/schema/enums/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn process_variant(
generics_output: &mut schema::GenericsOutput,
) -> syn::Result<VariantOutput> {
let variant_name = variant.ident.to_token_stream().to_string();
let full_variant_name = format!("{}{}", enum_name, variant_name);
let full_variant_name = format!("___{}{}", enum_name, variant_name);
let full_variant_ident = Ident::new(&full_variant_name, Span::call_site());

schema::visit_struct_fields(&variant.fields, &mut generics_output.params_visitor)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: pretty_print_syn_str(&actual).unwrap()
---
impl borsh::BorshSchema for X {
fn declaration() -> borsh::schema::Declaration {
"X".to_string()
format!("{}::{}", std::module_path!(), "X")
}
fn add_definitions_recursively(
definitions: &mut borsh::__private::maybestd::collections::BTreeMap<
Expand All @@ -15,44 +15,44 @@ impl borsh::BorshSchema for X {
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct XA;
struct ___XA;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct XB;
struct ___XB;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct XC;
struct ___XC;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct XD;
struct ___XD;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct XE;
struct ___XE;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct XF;
<XA as borsh::BorshSchema>::add_definitions_recursively(definitions);
<XB as borsh::BorshSchema>::add_definitions_recursively(definitions);
<XC as borsh::BorshSchema>::add_definitions_recursively(definitions);
<XD as borsh::BorshSchema>::add_definitions_recursively(definitions);
<XE as borsh::BorshSchema>::add_definitions_recursively(definitions);
<XF as borsh::BorshSchema>::add_definitions_recursively(definitions);
struct ___XF;
<___XA as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___XB as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___XC as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___XD as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___XE as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___XF as borsh::BorshSchema>::add_definitions_recursively(definitions);
let definition = borsh::schema::Definition::Enum {
tag_width: 1,
variants: borsh::__private::maybestd::vec![
(u8::from(0u8) as i64, "A".into(), < XA as borsh::BorshSchema >
::declaration()), (u8::from(1u8) as i64, "B".into(), < XB as
(u8::from(0u8) as i64, "A".into(), < ___XA as borsh::BorshSchema >
::declaration()), (u8::from(1u8) as i64, "B".into(), < ___XB as
borsh::BorshSchema > ::declaration()), (u8::from(2u8) as i64, "C".into(),
< XC as borsh::BorshSchema > ::declaration()), (u8::from(3u8) as i64, "D"
.into(), < XD as borsh::BorshSchema > ::declaration()), (u8::from(4u8) as
i64, "E".into(), < XE as borsh::BorshSchema > ::declaration()),
(u8::from(5u8) as i64, "F".into(), < XF as borsh::BorshSchema >
::declaration())
< ___XC as borsh::BorshSchema > ::declaration()), (u8::from(3u8) as i64,
"D".into(), < ___XD as borsh::BorshSchema > ::declaration()),
(u8::from(4u8) as i64, "E".into(), < ___XE as borsh::BorshSchema >
::declaration()), (u8::from(5u8) as i64, "F".into(), < ___XF as
borsh::BorshSchema > ::declaration())
],
};
borsh::schema::add_definition(
Expand All @@ -62,4 +62,3 @@ impl borsh::BorshSchema for X {
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: pretty_print_syn_str(&actual).unwrap()
---
impl borsh::BorshSchema for X {
fn declaration() -> borsh::schema::Declaration {
"X".to_string()
format!("{}::{}", std::module_path!(), "X")
}
fn add_definitions_recursively(
definitions: &mut borsh::__private::maybestd::collections::BTreeMap<
Expand All @@ -15,44 +15,44 @@ impl borsh::BorshSchema for X {
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct XA;
struct ___XA;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct XB;
struct ___XB;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct XC;
struct ___XC;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct XD;
struct ___XD;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct XE;
struct ___XE;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct XF;
<XA as borsh::BorshSchema>::add_definitions_recursively(definitions);
<XB as borsh::BorshSchema>::add_definitions_recursively(definitions);
<XC as borsh::BorshSchema>::add_definitions_recursively(definitions);
<XD as borsh::BorshSchema>::add_definitions_recursively(definitions);
<XE as borsh::BorshSchema>::add_definitions_recursively(definitions);
<XF as borsh::BorshSchema>::add_definitions_recursively(definitions);
struct ___XF;
<___XA as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___XB as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___XC as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___XD as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___XE as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___XF as borsh::BorshSchema>::add_definitions_recursively(definitions);
let definition = borsh::schema::Definition::Enum {
tag_width: 1,
variants: borsh::__private::maybestd::vec![
(u8::from(0) as i64, "A".into(), < XA as borsh::BorshSchema >
::declaration()), (u8::from(20) as i64, "B".into(), < XB as
(u8::from(0) as i64, "A".into(), < ___XA as borsh::BorshSchema >
::declaration()), (u8::from(20) as i64, "B".into(), < ___XB as
borsh::BorshSchema > ::declaration()), (u8::from(20 + 1) as i64, "C"
.into(), < XC as borsh::BorshSchema > ::declaration()), (u8::from(20 + 1
+ 1) as i64, "D".into(), < XD as borsh::BorshSchema > ::declaration()),
(u8::from(10) as i64, "E".into(), < XE as borsh::BorshSchema >
::declaration()), (u8::from(10 + 1) as i64, "F".into(), < XF as
borsh::BorshSchema > ::declaration())
.into(), < ___XC as borsh::BorshSchema > ::declaration()), (u8::from(20 +
1 + 1) as i64, "D".into(), < ___XD as borsh::BorshSchema >
::declaration()), (u8::from(10) as i64, "E".into(), < ___XE as
borsh::BorshSchema > ::declaration()), (u8::from(10 + 1) as i64, "F"
.into(), < ___XF as borsh::BorshSchema > ::declaration())
],
};
borsh::schema::add_definition(
Expand All @@ -62,4 +62,3 @@ impl borsh::BorshSchema for X {
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: pretty_print_syn_str(&actual).unwrap()
---
impl borsh::BorshSchema for A {
fn declaration() -> borsh::schema::Declaration {
"A".to_string()
format!("{}::{}", std::module_path!(), "A")
}
fn add_definitions_recursively(
definitions: &mut borsh::__private::maybestd::collections::BTreeMap<
Expand All @@ -15,35 +15,35 @@ impl borsh::BorshSchema for A {
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct ABacon;
struct ___ABacon;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct AEggs;
struct ___AEggs;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct ASalad(Tomatoes, Cucumber, Oil);
struct ___ASalad(Tomatoes, Cucumber, Oil);
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct ASausage {
struct ___ASausage {
wrapper: Wrapper,
filling: Filling,
}
<ABacon as borsh::BorshSchema>::add_definitions_recursively(definitions);
<AEggs as borsh::BorshSchema>::add_definitions_recursively(definitions);
<ASalad as borsh::BorshSchema>::add_definitions_recursively(definitions);
<ASausage as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___ABacon as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___AEggs as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___ASalad as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___ASausage as borsh::BorshSchema>::add_definitions_recursively(definitions);
let definition = borsh::schema::Definition::Enum {
tag_width: 1,
variants: borsh::__private::maybestd::vec![
(u8::from(0u8) as i64, "Bacon".into(), < ABacon as borsh::BorshSchema >
::declaration()), (u8::from(1u8) as i64, "Eggs".into(), < AEggs as
(u8::from(0u8) as i64, "Bacon".into(), < ___ABacon as borsh::BorshSchema
> ::declaration()), (u8::from(1u8) as i64, "Eggs".into(), < ___AEggs as
borsh::BorshSchema > ::declaration()), (u8::from(2u8) as i64, "Salad"
.into(), < ASalad as borsh::BorshSchema > ::declaration()),
(u8::from(3u8) as i64, "Sausage".into(), < ASausage as borsh::BorshSchema
> ::declaration())
.into(), < ___ASalad as borsh::BorshSchema > ::declaration()),
(u8::from(3u8) as i64, "Sausage".into(), < ___ASausage as
borsh::BorshSchema > ::declaration())
],
};
borsh::schema::add_definition(
Expand All @@ -53,4 +53,3 @@ impl borsh::BorshSchema for A {
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ where
< C as borsh::BorshSchema > ::declaration(), < W as borsh::BorshSchema >
::declaration()
];
format!(r#"{}<{}>"#, "A", params.join(", "))
format!(r#"{}::{}<{}>"#, std::module_path!(), "A", params.join(", "))
}
fn add_definitions_recursively(
definitions: &mut borsh::__private::maybestd::collections::BTreeMap<
Expand All @@ -23,34 +23,34 @@ where
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct ABacon;
struct ___ABacon;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct AEggs;
struct ___AEggs;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct ASalad<C>(Tomatoes, C, Oil);
struct ___ASalad<C>(Tomatoes, C, Oil);
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct ASausage<W> {
struct ___ASausage<W> {
wrapper: W,
filling: Filling,
}
<ABacon as borsh::BorshSchema>::add_definitions_recursively(definitions);
<AEggs as borsh::BorshSchema>::add_definitions_recursively(definitions);
<ASalad<C> as borsh::BorshSchema>::add_definitions_recursively(definitions);
<ASausage<W> as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___ABacon as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___AEggs as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___ASalad<C> as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___ASausage<W> as borsh::BorshSchema>::add_definitions_recursively(definitions);
let definition = borsh::schema::Definition::Enum {
tag_width: 1,
variants: borsh::__private::maybestd::vec![
(u8::from(0u8) as i64, "Bacon".into(), < ABacon as borsh::BorshSchema >
::declaration()), (u8::from(1u8) as i64, "Eggs".into(), < AEggs as
(u8::from(0u8) as i64, "Bacon".into(), < ___ABacon as borsh::BorshSchema
> ::declaration()), (u8::from(1u8) as i64, "Eggs".into(), < ___AEggs as
borsh::BorshSchema > ::declaration()), (u8::from(2u8) as i64, "Salad"
.into(), < ASalad < C > as borsh::BorshSchema > ::declaration()),
(u8::from(3u8) as i64, "Sausage".into(), < ASausage < W > as
.into(), < ___ASalad < C > as borsh::BorshSchema > ::declaration()),
(u8::from(3u8) as i64, "Sausage".into(), < ___ASausage < W > as
borsh::BorshSchema > ::declaration())
],
};
Expand All @@ -61,4 +61,3 @@ where
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ where
< U as borsh::BorshSchema > ::declaration(), < C as borsh::BorshSchema >
::declaration()
];
format!(r#"{}<{}>"#, "A", params.join(", "))
format!(r#"{}::{}<{}>"#, std::module_path!(), "A", params.join(", "))
}
fn add_definitions_recursively(
definitions: &mut borsh::__private::maybestd::collections::BTreeMap<
Expand All @@ -23,36 +23,39 @@ where
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct ABacon;
struct ___ABacon;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct AEggs;
struct ___AEggs;
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct ASalad<C>(Tomatoes, C, Oil);
struct ___ASalad<C>(Tomatoes, C, Oil);
#[allow(dead_code)]
#[derive(borsh::BorshSchema)]
#[borsh(crate = "borsh")]
struct ASausage<W, U> {
struct ___ASausage<W, U> {
#[borsh(skip)]
wrapper: W,
filling: Filling,
unexpected: U,
}
<ABacon as borsh::BorshSchema>::add_definitions_recursively(definitions);
<AEggs as borsh::BorshSchema>::add_definitions_recursively(definitions);
<ASalad<C> as borsh::BorshSchema>::add_definitions_recursively(definitions);
<ASausage<W, U> as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___ABacon as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___AEggs as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___ASalad<C> as borsh::BorshSchema>::add_definitions_recursively(definitions);
<___ASausage<
W,
U,
> as borsh::BorshSchema>::add_definitions_recursively(definitions);
let definition = borsh::schema::Definition::Enum {
tag_width: 1,
variants: borsh::__private::maybestd::vec![
(u8::from(0u8) as i64, "Bacon".into(), < ABacon as borsh::BorshSchema >
::declaration()), (u8::from(1u8) as i64, "Eggs".into(), < AEggs as
(u8::from(0u8) as i64, "Bacon".into(), < ___ABacon as borsh::BorshSchema
> ::declaration()), (u8::from(1u8) as i64, "Eggs".into(), < ___AEggs as
borsh::BorshSchema > ::declaration()), (u8::from(2u8) as i64, "Salad"
.into(), < ASalad < C > as borsh::BorshSchema > ::declaration()),
(u8::from(3u8) as i64, "Sausage".into(), < ASausage < W, U > as
.into(), < ___ASalad < C > as borsh::BorshSchema > ::declaration()),
(u8::from(3u8) as i64, "Sausage".into(), < ___ASausage < W, U > as
borsh::BorshSchema > ::declaration())
],
};
Expand All @@ -63,4 +66,3 @@ where
);
}
}

Loading
Loading