Function magnus::encoding::copy

source ·
pub fn copy<T, U>(dst: T, src: U) -> Result<(), Error>
Expand description

Compies the encoding from src to dst.

This does not reconcode dst.

Similar to EncodingCapable::enc_associate, except takes the encoding of src rather than an encoding object or index.

§Examples

use magnus::{encoding, prelude::*, RString};

let a = RString::new("a");
assert!(a.enc_get() == encoding::Index::utf8());
let b = RString::new("b");
assert!(b.enc_get() == encoding::Index::utf8());

a.enc_set(encoding::Index::usascii()).unwrap();
encoding::copy(b, a).unwrap();

assert!(b.enc_get() == encoding::Index::usascii());