-
Notifications
You must be signed in to change notification settings - Fork 78
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!: add Definition::Primitive
#222
Conversation
f3eae2f
to
ff32f39
Compare
@@ -326,6 +346,7 @@ mod tests { | |||
test_ok::<Option<()>>(1); | |||
test_ok::<Option<u8>>(2); | |||
test_ok::<core::result::Result<u8, usize>>(9); | |||
test_ok::<core::result::Result<u8, Vec<u8>>>(1 + 4 + MAX_LEN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current master results in this fail of test assertion:
---- schema::container_ext::max_size::tests::max_serialized_size_built_in_types stdout ----
thread 'schema::container_ext::max_size::tests::max_serialized_size_built_in_types' panicked at 'assertion failed: `(left == right)`
left: `Ok(9)`,
right: `Err(MissingDefinition("Vec<u8>"))`'
ff32f39
to
f384415
Compare
@@ -48,7 +48,7 @@ fn validate_for_derived_types() { | |||
test_ok::<Empty>(); | |||
test_ok::<Named>(); | |||
test_ok::<Unnamed>(); | |||
test_ok::<BorshSchemaContainer>(); | |||
// test_ok::<BorshSchemaContainer>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thread 'validate_for_derived_types' panicked at 'assertion failed: `(left == right)`
left: `Ok(())`,
right: `Err(MissingDefinition("string"))`'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where str
and String
would be
pub enum Definition {
/// `special_encoding` of `true` indicates that not all
/// sequences of `elements` type, allowed by the type, are valid with respect
/// to `Sequence` type being defined
Sequence { elements: Declaration, special_encoding: bool },
...
}
impl BorshSchema for String {
#[inline]
fn add_definitions_recursively(
definitions: &mut BTreeMap<Declaration, Definition>,
) {
let definition = Definition::Sequence {
elements: u8::declaration(),
special_encoding: true,
};
add_definition(Self::declaration(), definition, definitions);
u8::add_definitions_recursively(definitions);
}
#[inline]
fn declaration() -> Declaration {
"string".into()
}
}
or just
let definition = Definition::Sequence {
elements: u8::declaration(),
};
46e4dfc
to
1e6acb9
Compare
1e6acb9
to
8ef4b61
Compare
cbbc1ef
to
66bf52e
Compare
this pr takes a step back and attempts to add definitions to all types, supported by
BorshSchema
,in order to allow remove comments like
from various methods