Lines
100 %
Functions
38.81 %
Branches
use std::borrow::Cow;
use bonsaidb::core::key::{Key, KeyEncoding};
#[test]
fn tuple_struct() {
#[derive(Clone, Debug, Key)]
struct Test(i32, i32, String);
assert_eq!(
&[0, 0, 0, 1, 0, 0, 0, 2, 116, 101, 115, 116, 0, 4],
Test(1, 2, "test".into()).as_ord_bytes().unwrap().as_ref()
)
}
fn transparent_structs() {
struct Test(i32);
struct TestNamed {
named: i32,
assert_eq!(&[0, 0, 0, 1], Test(1).as_ord_bytes().unwrap().as_ref());
&[0, 0, 0, 1],
TestNamed { named: 1 }.as_ord_bytes().unwrap().as_ref()
fn struct_struct() {
struct Test {
a: i32,
b: String,
&[255, 255, 255, 214, 109, 101, 97, 110, 105, 110, 103, 0, 7],
Test {
a: -42,
b: "meaning".into()
.as_ord_bytes()
.unwrap()
.as_ref()
fn unit_struct() {
struct Test;
assert_eq!(b"", Test.as_ord_bytes().unwrap().as_ref())
fn r#enum() {
enum Test {
A,
B(i32, String),
C { a: String, b: i32 },
assert_eq!(&[128, 0, 1], Test::A.as_ord_bytes().unwrap().as_ref());
&[129, 0, 0, 0, 0, 2, 97, 0, 1, 1],
Test::B(2, "a".into()).as_ord_bytes().unwrap().as_ref()
);
&[130, 0, 98, 0, 0, 0, 0, 3, 1, 1],
Test::C {
a: "b".into(),
b: 3
fn enum_repr() {
#[repr(u8)]
enum Test1 {
A = 1,
B = 2,
#[key(enum_repr = u8)]
enum Test2 {
A = 2,
B = 1,
Test1::A.as_ord_bytes().unwrap(),
Test2::B.as_ord_bytes().unwrap()
assert_eq!(Test1::A.as_ord_bytes().unwrap().as_ref(), &[1]);
Test1::B.as_ord_bytes().unwrap(),
Test2::A.as_ord_bytes().unwrap()
assert_eq!(Test1::B.as_ord_bytes().unwrap().as_ref(), &[2]);
fn enum_u64() {
#[repr(u64)]
A = 0,
B = u64::MAX - 1,
C,
Test::C.as_ord_bytes().unwrap().as_ref(),
&[255, 255, 255, 255, 255, 255, 255, 255]
fn lifetime() {
struct Test<'a, 'b>(Cow<'a, str>, Cow<'b, str>);
&[97, 0, 98, 0, 1, 1],
Test("a".into(), "b".into())