You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: binary_literal.rs
    path of file: ./repos/tikv/components/tidb_query_datatype/src/codec/mysql
    
    the code of the file until where you have to start completion: // Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.

use std::{
    cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd},
    string::ToString,
};

use crate::{
    codec::{error::Error, Result},
    expr::EvalContext,
};

/// BinaryLiteral is the internal type for storing bit / hex literal type.
#[derive(Debug)]
pub struct BinaryLiteral(Vec<u8>);

fn trim_leading_zero_bytes(bytes: &[u8]) -> &[u8] {
    if bytes.is_empty() {
        return bytes;
    }
    let (pos, _) = bytes
        .iter()
        .enumerate()
        .find(|(_, &x)| x != 0)
        .unwrap_or((bytes.len() - 1, &0));
    &bytes[pos..]
}

/// Returns the int value for the literal.
pub fn to_uint(ctx: &mut EvalContext, bytes: &[u8]) -> Result<u64> {
    let bytes = trim_leading_zero_bytes(bytes);
    if bytes.is_empty() {
        return Ok(0);
    }
    if bytes.len() > 8 {
        ctx.handle_truncate_err(Error::truncated_wrong_val(
            "BINARY",
            BinaryLiteral(bytes.to_owned()).to_string(),
        ))?;
        return Ok(u64::MAX);
    }
    let val = bytes.iter().fold(0, |acc, x| acc << 8 | (u64::from(*x)));
    Ok(val)
}

impl BinaryLiteral {
    /// from_u64 creates a new BinaryLiteral instance by the given uint value in
    /// BigEndian. byte size will be used as the length
    
    fn test_binary_literal_from_bit_str() {
        let cs = vec![
            ("b''", vec![], false),
            ("B''", vec![], false),
            ("0b''", vec![], true),
            ("0b0", vec![0x0], false),
            ("b'0'", vec![0x0], false),
            ("B'0'", vec![0x0], false),
            ("0B0", vec![], true),
            ("0b123", vec![], true),
            ("b'123'", vec![], true),
            ("0b'1010'", vec![], true),
            ("0b0000000", vec![0x0], false),
            ("b'0000000'", vec![0x0], false),
            ("B'0000000'", vec![0x0], false),
            ("0b00000000", vec![0x0], false),
            ("b'00000000'", vec![0x0], false),
            ("B'00000000'", vec![0x0], false),
            ("0b000000000", vec![0x0, 0x0], false),
            ("b'000000000'", vec![0x0, 0x0], false),
            ("B'000000000'", vec![0x0, 0x0], false),
            ("0b1", vec![0x1], false),
            ("b'1'", vec![0x1], false),
            ("B'1'", vec![0x1], false),
            ("0b00000001", vec![0x1], false),
            ("b'00000001'", vec![0x1], false),
            ("B'00000001'", vec![0x1], false),
            ("0b000000010", vec![0x0, 0x2], false),
            ("b'000000010'", vec![0x0, 0x2], false),
            ("B'000000010'", vec![0x0, 0x2], false),
            ("0b000000001", vec![0x0, 0x1], false),
            ("b'000000001'", vec![0x0, 0x1], false),
            ("B'000000001'", vec![0x0, 0x1], false),
            ("0b11111111", vec![0xFF], false),
            ("b'11111111'", vec![0xFF], false),
            ("B'11111111'", vec![0xFF], false),
            ("0b111111111", vec![0x1, 0xFF], false),
            ("b'111111111'", vec![0x1, 0xFF], false),
            ("B'111111111'", vec![0x1, 0xFF], false),
            (
                "0b1101000011001010110110001101100011011110010000001110111011011110111001001101100011001000010000001100110011011110110111100100000011000100110000101110010",
                b"hello world foo bar".to_vec(),
                false,
            ),
            (
                "b'1101000011001010110110001101100011011110010000001110111011011110111001001101100011001000010000001100110011011110110111100100000011000100110000101110010'",
                b"hello world foo bar".to_vec(),
                false,
            ),
            (
                "B'1101000011001010110110001101100011011110010000001110111011011110111001001101100011001000010000001100110011011110110111100100000011000100110000101110010'",
                b"hello world foo bar".to_vec(),
                false,
            ),
            (
                "0b01101000011001010110110001101100011011110010000001110111011011110111001001101100011001000010000001100110011011110110111100100000011000100110000101110010",
                b"hello world foo bar".to_vec(),
                false,
            ),
            (
                "b'01101000011001010110110001101100011011110010000001110111011011110111001001101100011001000010000001100110011011110110111100100000011000100110000101110010'",
                b"hello world foo bar".to_vec(),
                false,
            ),
            (
                "B'01101000011001010110110001101100011011110010000001110111011011110111001001101100011001000010000001100110011011110110111100100000011000100110000101110010'",
                b"hello world foo bar".to_vec(),
                false,
            ),
        ];

        for (input, exptected, err) in cs {
            if err {
                let lit = BinaryLiteral::from_bit_str(input);
                assert!(lit.is_err(), "input: {}, lit: {:?}", input, lit);
            } else {
                let lit = BinaryLiteral::from_bit_str(input).unwrap();
                assert_eq!(lit.0, exptected);
            }
        }
    }