[][src]Trait codepage_437::IntoCp437

pub trait IntoCp437<T> {
    fn into_cp437(self, dialect: &Cp437Dialect) -> Result<T, IntoCp437Error>;
}

Move Unicode data to a container of cp437 data.

Examples

Good:

let cp437 = vec![0x4C, 0x6F, 0x63, 0x61, 0x6C, 0x20, 0x6E, 0x65, 0x77, 0x73, 0x20, 0x72, 0x65,
                 0x70, 0x6F, 0x72, 0x74, 0x73, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x74, 0x68,
                 0x65, 0x20, 0x9E, 0xAB, 0x20, 0x6D, 0x69, 0x6C, 0x6C, 0x69, 0x6F, 0x6E, 0x20,
                 0x41, 0x69, 0x72, 0x20, 0x4D, 0x65, 0x6C, 0x61, 0x6E, 0x65, 0x73, 0x69, 0x91,
                 0x20, 0x61, 0x69, 0x72, 0x63, 0x72, 0x61, 0x66, 0x74, 0x20, 0x68, 0x61, 0x73,
                 0x20, 0x63, 0x72, 0x61, 0x73, 0x68, 0x65, 0x64, 0x20, 0x74, 0x68, 0x69, 0x73,
                 0x20, 0x6D, 0x6F, 0x72, 0x6E, 0x69, 0x6E, 0x67, 0x20, 0x61, 0x72, 0x6F, 0x75,
                 0x6E, 0x64, 0x20, 0x39, 0x3A, 0x30, 0x30, 0x61, 0x6D, 0x2E];
let unicode =
    "Local news reports that the ₧½ million Air Melanesiæ aircraft has crashed this morning around 9:00am.".to_string();

assert_eq!(unicode.into_cp437(&CP437_CONTROL), Ok(cp437));  // unicode is moved out of

Unrepresentable:

// Ż cannot be represented in cp437
let unicode = "Jurek je żurek w żupanie.".to_string();

let error = unicode.into_cp437(&CP437_CONTROL).unwrap_err();  // unicode is moved out of
assert_eq!(error.as_str(), "Jurek je żurek w żupanie.");
assert_eq!(error.cp437_error().representable_up_to, 9);

let unicode = error.into_string();                   // unicode now the same as original

Required Methods

Do the conversion.

Implementations on Foreign Types

impl IntoCp437<Vec<u8>> for String
[src]

Implementors