pub fn to_string(&self) -> Result<String, FromUtf32Error> {
        let chars: Vec<Option<char>> = self.inner.iter().map(|c| char::from_u32(*c)).collect();
        if chars.iter().any(|c| c.is_none()) {
            return Err(FromUtf32Error());
        }
        let size = chars.iter().filter_map(|o| o.map(|c| c.len_utf8())).sum();
        let mut vec = Vec::with_capacity(size);
        unsafe { vec.set_len(size) };
        let mut i = 0;
        for c in chars.iter().filter_map(|&o| o) {
            c.encode_utf8(&mut vec[i..]);
            i += c.len_utf8();
        }
        Ok(unsafe { String::from_utf8_unchecked(vec) })
    }
/// Copies the wide string to a `String` if it contains valid UTF-32 data.
///
/// # Failures
///
/// Returns an error if the string contains any invalid UTF-32 data.
///
/// # Examples
///
/// ```rust
/// use widestring::U32String;
/// let s = "MyString";
/// // Create a wide string from the string
/// let wstr = U32String::from_str(s);
/// // Create a regular string from the wide string
/// let s2 = wstr.to_string().unwrap();
///
/// assert_eq!(s2, s);
/// ```
Copies the wide string to a `String` if it contains valid UTF-32 data.
Copies the wide string to a ` String ` if it contains valid UTF - 32 data .
pub fn to_string(&self) -> Result<String, FromUtf32Error> {
        let chars: Vec<Option<char>> = self.inner.iter().map(|c| char::from_u32(*c)).collect();
        if chars.iter().any(|c| c.is_none()) {
            return Err(FromUtf32Error());
        }
        let size = chars.iter().filter_map(|o| o.map(|c| c.len_utf8())).sum();
        let mut vec = Vec::with_capacity(size);
        unsafe { vec.set_len(size) };
        let mut i = 0;
        for c in chars.iter().filter_map(|&o| o) {
            c.encode_utf8(&mut vec[i..]);
            i += c.len_utf8();
        }
        Ok(unsafe { String::from_utf8_unchecked(vec) })
    }
pub fn to_string ( & self ) -> Result < String , FromUtf32Error > { let chars : Vec < Option < char > > = self . inner . iter ( ) . map ( | c | char :: from_u32 ( * c ) ) . collect ( ) ; if chars . iter ( ) . any ( | c | c . is_none ( ) ) { return Err ( FromUtf32Error ( ) ) ; } let size = chars . iter ( ) . filter_map ( | o | o . map ( | c | c . len_utf8 ( ) ) ) . sum ( ) ; let mut vec = Vec :: with_capacity ( size ) ; unsafe { vec . set_len ( size ) } ; let mut i = 0 ; for c in chars . iter ( ) . filter_map ( | & o | o ) { c . encode_utf8 ( & mut vec [ i .. ] ) ; i += c . len_utf8 ( ) ; } Ok ( unsafe { String :: from_utf8_unchecked ( vec ) } ) }
Copies the wide string to a `String` if it contains valid UTF-32 data.
Copies the wide string to a ` String ` if it contains valid UTF - 32 data .
&self
&self
failures
Returns an error if the string contains any invalid UTF-32 data.
Returns an error if the string contains any invalid UTF - 32 data .
examples
```rust
use widestring::U32String;
let s = "MyString";
Create a wide string from the string
let wstr = U32String::from_str(s);
Create a regular string from the wide string
let s2 = wstr.to_string().unwrap().


` ` ` rust use widestring :: U32String ; let s = " MyString " ; Create a wide string from the string let wstr = U32String :: from_str ( s ) ; Create a regular string from the wide string let s2 = wstr . to_string () . unwrap () .