pkstrings: Remove TryFrom<String> for PKString
To force the user to use .as_st so that it's more obvious that we don't take the ownership of the String. Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
1a9c5e0060
commit
7fa4a2079a
4 changed files with 2 additions and 18 deletions
|
@ -29,7 +29,7 @@ fn main() {
|
|||
|
||||
if args.len() == 2 {
|
||||
// Convert String to PKString and then to Vec<u8>
|
||||
let tmp: Vec<u8> = PKString::try_from(args[1].clone()).unwrap().into();
|
||||
let tmp: Vec<u8> = PKString::try_from(args[1].as_str()).unwrap().into();
|
||||
println!("{:#02x?}", tmp);
|
||||
} else if args.len() == 3 && args[1] == String::from("rev") {
|
||||
// Consure chars 2 by 2 and convert to u8.
|
||||
|
|
|
@ -40,7 +40,7 @@ fn read_data(data: Vec<u8>) {
|
|||
|
||||
for (offset, ord) in data.iter().enumerate() {
|
||||
// Read current chr
|
||||
if let Ok(pkstr) = PKString::try_from(*ord) {
|
||||
if let Ok(pkstr) = PKString::try_from(&[*ord][..]) {
|
||||
buffer.push(String::from(pkstr));
|
||||
} else {
|
||||
if buffer.len() >= 4 {
|
||||
|
|
|
@ -192,14 +192,6 @@ impl TryFrom<&str> for PKString {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for PKString {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(data: String) -> Result<PKString, Error> {
|
||||
PKString::try_from(data.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PKString> for Vec<u8> {
|
||||
fn from(pkstr: PKString) -> Vec<u8> {
|
||||
pkstr.0
|
||||
|
|
|
@ -104,14 +104,6 @@ fn test_into_vec_u8() {
|
|||
assert_eq!(res, GARY_SLICE_U8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_string() {
|
||||
match PKString::try_from(String::from(GARY_STR)) {
|
||||
Ok(pkstr) => assert_eq!(pkstr, PKString::try_from(GARY_SLICE_U8).unwrap()),
|
||||
Err(_) => panic!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_as_slice_u8() {
|
||||
let pkstr: PKString = PKString::try_from(GARY_SLICE_U8).unwrap();
|
||||
|
|
Loading…
Reference in a new issue