Trait BorrowFromCp437

Source
pub trait BorrowFromCp437<'c, T: ?Sized> {
    // Required method
    fn borrow_from_cp437(cp437: &'c T, dialect: &Cp437Dialect) -> Self;
}
Expand description

Try to borrow data encoded in cp437 as a Unicode container of the specified type.

If that cannot be done, clone it.

§Examples

let cp437 = [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.";

assert_eq!(Cow::borrow_from_cp437(&cp437[..], &CP437_CONTROL),
           String::borrow_from_cp437(&cp437[..], &CP437_CONTROL));
assert_eq!(Cow::borrow_from_cp437(&cp437[..], &CP437_CONTROL), unicode);

Required Methods§

Source

fn borrow_from_cp437(cp437: &'c T, dialect: &Cp437Dialect) -> Self

Do the conversion.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'c, T: AsRef<[u8]> + ?Sized> BorrowFromCp437<'c, T> for Cow<'c, str>

Source§

fn borrow_from_cp437(cp437: &'c T, dialect: &Cp437Dialect) -> Self

Source§

impl<'c, T: AsRef<[u8]> + ?Sized> BorrowFromCp437<'c, T> for String

Source§

fn borrow_from_cp437(cp437: &'c T, dialect: &Cp437Dialect) -> Self

Implementors§