Crates.io | petscii |
lib.rs | petscii |
version | 0.2.1 |
source | src |
created_at | 2023-10-13 07:55:02.657329 |
updated_at | 2023-10-13 09:16:41.74819 |
description | String library for Commodore PETSCII. |
homepage | |
repository | https://github.com/jkorinth/petscii |
max_upload_size | |
id | 1002063 |
size | 54,071 |
Support library for Commodore PETSCII strings.
let data = [b'A', b'B', b'C'];
let petscii = petscii::PetsciiString::from(&data);
assert_eq!("ABC", petscii.to_string());
let petscii = petscii::PetsciiString::try_from("ANSWER IS 42").unwrap();
// truncate case:
let data_trunc: petscii::Result<[u8; 7]> = petscii.clone().try_into();
assert!(data_trunc.is_err());
// extended buffer case (beware of Commodore's NO_BREAK_SPACE filling):
let data_ext: [u8; 16] = petscii.clone().try_into().unwrap();
assert_eq!(
format!("{}", petscii::PetsciiString::from(&data_ext)),
"ANSWER IS 42\u{a0}\u{a0}\u{a0}\u{a0}"
);
Beware that the From<[u8]>
implementation silently drops non-printables.
If that is not what you want, use TryFrom
:
let petscii = petscii::encode("Answer is 42");
assert_eq!(*petscii, [b'A', b' ', b' ', b'4', b'2']);
let fpetscii = petscii::try_encode("Answer is 42");
assert!(fpetscii.is_err());