Skip to content

Commit

Permalink
feat: impl BorshSchema for char
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Oct 16, 2023
1 parent e18f3b3 commit 52f719e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions borsh/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ macro_rules! impl_for_primitives {
}

impl_for_primitives!(bool => 1; f32 => 4; f64 => 8; i8 => 1; i16 => 2; i32 => 4; i64 => 8; i128 => 16);
impl_for_primitives!(char => 4);
impl_for_primitives!(u8 => 1; u16 => 2; u32 => 4; u64 => 8; u128 => 16);
impl_for_renamed_primitives!(isize: i64 => 8);
impl_for_renamed_primitives!(usize: u64 => 8);
Expand Down Expand Up @@ -737,6 +738,20 @@ mod tests {
);
}

#[test]
fn char() {
let actual_name = char::declaration();
let mut actual_defs = map!();
char::add_definitions_recursively(&mut actual_defs);
assert_eq!("char", actual_name);
assert_eq!(
map! {
"char" => Definition::Primitive(4)
},
actual_defs
);
}

#[test]
fn nested_option() {
let actual_name = Option::<Option<u64>>::declaration();
Expand Down
1 change: 1 addition & 0 deletions borsh/src/schema/container_ext/max_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ mod tests {
fn max_serialized_size_primitives() {
test_ok::<()>(0);
test_ok::<bool>(1);
test_ok::<char>(4);

test_ok::<f32>(4);
test_ok::<f64>(8);
Expand Down

0 comments on commit 52f719e

Please sign in to comment.