fn from_str(s: &str) -> Result<BString, Self::Err>
    {
        // Avoid unnecessary allocations when the string is empty.
        // Null and empty BSTRs should be treated as equal.
        // See https://blogs.msdn.microsoft.com/ericlippert/2003/09/12/erics-complete-guide-to-bstr-semantics/
        if s.is_empty() {
            return Ok(BString(std::ptr::null_mut()));
        }

        unsafe {
            let chars = s.encode_utf16().collect::<Vec<_>>();
            let bstr = os::SysAllocStringLen(chars.as_ptr(), chars.len() as u32);

            // Memory issues are traditionally fatal in Rust and do not cause
            // Err-results.
            if bstr.0.is_null() {
                panic!("Allocating BStr failed.");
            }

            Ok(BString::from_ptr(bstr.0))
        }
    }
/// Converts a Rust string into a `BString`.
Converts a Rust string into a `BString`.
Converts a Rust string into a ` BString ` .
fn from_str(s: &str) -> Result<BString, Self::Err>
    {
        // Avoid unnecessary allocations when the string is empty.
        // Null and empty BSTRs should be treated as equal.
        // See https://blogs.msdn.microsoft.com/ericlippert/2003/09/12/erics-complete-guide-to-bstr-semantics/
        if s.is_empty() {
            return Ok(BString(std::ptr::null_mut()));
        }
        unsafe {
            let chars = s.encode_utf16().collect::<Vec<_>>();
            let bstr = os::SysAllocStringLen(chars.as_ptr(), chars.len() as u32);
            // Memory issues are traditionally fatal in Rust and do not cause
            // Err-results.
            if bstr.0.is_null() {
                panic!("Allocating BStr failed.");
            }
            Ok(BString::from_ptr(bstr.0))
        }
    }
fn from_str ( s : & str ) -> Result < BString , Self :: Err > { // Avoid unnecessary allocations when the string is empty. // Null and empty BSTRs should be treated as equal. // See https://blogs.msdn.microsoft.com/ericlippert/2003/09/12/erics-complete-guide-to-bstr-semantics/ if s . is_empty ( ) { return Ok ( BString ( std :: ptr :: null_mut ( ) ) ) ; } unsafe { let chars = s . encode_utf16 ( ) . collect :: < Vec < _ > > ( ) ; let bstr = os :: SysAllocStringLen ( chars . as_ptr ( ) , chars . len ( ) as u32 ) ; // Memory issues are traditionally fatal in Rust and do not cause // Err-results. if bstr . 0 . is_null ( ) { panic ! ( " " ) ; } Ok ( BString :: from_ptr ( bstr . 0 ) ) } }
Converts a Rust string into a `BString`.
Converts a Rust string into a ` BString ` .
s
&str
s
&str