fn force_encoding(&mut self, enc: Encoding) -> Result<Self, AnyException> {
        if string::is_lockedtmp(self.value()) {
            return Err(AnyException::new("RuntimeError", Some("can't modify string; temporarily locked")));
        }

        if self.is_frozen() {
            return Err(AnyException::new("FrozenError", Some("can't modify frozen String")));
        }

        self.value = encoding::force_encoding(self.value(), enc.value());
        encoding::coderange_clear(self.value);

        Ok(Self::from(self.value()))
    }
/// Changes the encoding to encoding and returns `Result<Self, AnyException>`.
///
/// # Examples
///
/// ```
/// use rutie::{RString, VM, EncodingSupport, Encoding};
/// # VM::init();
///
/// let mut string = RString::new_utf8("Hello");
/// string.force_encoding(Encoding::us_ascii());
///
/// assert_eq!(string.encoding().name(), "US-ASCII");
/// ```
///
/// Ruby:
///
/// ```ruby
/// string = "Hello"
/// string.force_encoding(Encoding::US_ASCII)
///
/// string.encoding.name == "US-ASCII"
/// ```
///
/// ```
/// use rutie::{RString, VM, EncodingSupport, Encoding, Object, Exception};
/// # VM::init();
///
/// let mut string = RString::new_utf8("Hello");
/// string.force_encoding(Encoding::utf8());
/// string.freeze();
/// let result = string.force_encoding(Encoding::us_ascii());
///
/// match result {
///     Ok(_) => assert_eq!("This is a bad path.", "You shouldn't get this message."),
///     Err(happy_path) => assert_eq!(happy_path.message(), "can\'t modify frozen String"),
/// }
/// ```
Changes the encoding to encoding and returns `Result`.
Changes the encoding to encoding and returns ` Result ` .
fn force_encoding(&mut self, enc: Encoding) -> Result<Self, AnyException> {
        if string::is_lockedtmp(self.value()) {
            return Err(AnyException::new("RuntimeError", Some("can't modify string; temporarily locked")));
        }
        if self.is_frozen() {
            return Err(AnyException::new("FrozenError", Some("can't modify frozen String")));
        }
        self.value = encoding::force_encoding(self.value(), enc.value());
        encoding::coderange_clear(self.value);
        Ok(Self::from(self.value()))
    }
fn force_encoding ( & mut self , enc : Encoding ) -> Result < Self , AnyException > { if string :: is_lockedtmp ( self . value ( ) ) { return Err ( AnyException :: new ( " " , Some ( " " ) ) ) ; } if self . is_frozen ( ) { return Err ( AnyException :: new ( " " , Some ( " " ) ) ) ; } self . value = encoding :: force_encoding ( self . value ( ) , enc . value ( ) ) ; encoding :: coderange_clear ( self . value ) ; Ok ( Self :: from ( self . value ( ) ) ) }
Changes the encoding to encoding and returns `Result<Self, AnyException>`.
Changes the encoding to encoding and returns ` Result<Self AnyException > ` .
&mut self
enc
Encoding
&mut self
enc
Encoding
examples
```
use rutie::{RString, VM, EncodingSupport, Encoding}.
` ` ` use rutie :: { RString VM EncodingSupport Encoding } .
vm::init();
let mut string = RString::new_utf8("Hello");
string.force_encoding(Encoding::us_ascii()).





```ruby
string = "Hello"
string.force_encoding(Encoding::US_ASCII)

string.encoding.name == "US-ASCII"
```

```
use rutie::{RString, VM, EncodingSupport, Encoding, Object, Exception}.
let mut string = RString :: new_utf8 ( " Hello " ) ; string . force_encoding ( Encoding :: us_ascii () ) . ` ` ` ruby string = " Hello " string . force_encoding ( Encoding :: US_ASCII ) string . encoding . name == " US - ASCII " ` ` ` ` ` ` use rutie :: { RString VM EncodingSupport Encoding Object Exception } .
vm::init();
let mut string = RString::new_utf8("Hello");
string.force_encoding(Encoding::utf8());
string.freeze();
let result = string.force_encoding(Encoding::us_ascii()).

match result {
Ok(_) => assert_eq!("This is a bad path.", "You shouldn't get this message."),
Err(happy_path) => assert_eq!(happy_path.message(), "can\'t modify frozen String"),
}
```
let mut string = RString :: new_utf8 ( " Hello " ) ; string . force_encoding ( Encoding :: utf8 () ) ; string . freeze () ; let result = string . force_encoding ( Encoding :: us_ascii () ) . match result { Ok ( _ ) = > assert_eq! ( " This is a bad path . " " You shouldn ' t get this message . " ) Err ( happy_path ) = > assert_eq! ( happy_path . message () " can \ ' t modify frozen String " ) } ` ` `