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

Need a prefix version to handle hex data more easily. #51

Open
yjhmelody opened this issue Jan 25, 2021 · 1 comment
Open

Need a prefix version to handle hex data more easily. #51

yjhmelody opened this issue Jan 25, 2021 · 1 comment

Comments

@yjhmelody
Copy link

Such as:

pub trait ToHexExt {
    /// Encode the hex strict representing `self` into the result with prefix `0x`. Lower case
    /// letters are used (e.g. `f9b4ca`)
    fn encode_hex_with_prefix<T: iter::FromIterator<char>>(&self) -> T;

    /// Encode the hex strict representing `self` into the result with prefix `0X`. Upper case
    /// letters are used (e.g. `F9B4CA`)
    fn encode_hex_upper_with_prefix<T: iter::FromIterator<char>>(&self) -> T;
}


impl <T: ToHex + AsRef<[u8]> >ToHexExt for T {
    fn encode_hex_with_prefix<U: iter::FromIterator<char>>(&self) -> U {
        encode_to_iter(HEX_CHARS_LOWER, &["0x".as_ref(), self.as_ref()].concat())
    }

    fn encode_hex_upper_with_prefix<U: iter::FromIterator<char>>(&self) -> U {
        encode_to_iter(HEX_CHARS_UPPER, &["0X".as_ref(), self.as_ref()].concat())
    }
}

But I find that maybe need a ext subdir for doing such work for all apis.

@ildar
Copy link

ildar commented Aug 20, 2021

and decoding counterpart also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants