NLINKER_RUST Telegram 1832
Преобразование сишной строки в &str можно сделать так:
pub fn safe_fun() -> Result<&'static str, Utf8Error> {
let char_ptr = unsafe { unsafe_fun() };
let c_str = unsafe { CStr::from_ptr(char_ptr) };
c_str.to_str()
}

Но нужно соблюсти 2 условия:
- сишная библиотека обязана не удалять строку
- сишная библиотека обязана не менять строку
Если соблюдение этих условий кажется проблематичным, то лучше сделать owned copy:
pub fn safe_fun() -> Result<String, Utf8Error> {
let char_ptr = unsafe { unsafe_fun() };
let c_str = unsafe { CStr::from_ptr(char_ptr) };
c_str.to_str().map(|s| s.to_owned())
}



tgoop.com/nlinker_rust/1832
Create:
Last Update:

Преобразование сишной строки в &str можно сделать так:

pub fn safe_fun() -> Result<&'static str, Utf8Error> {
let char_ptr = unsafe { unsafe_fun() };
let c_str = unsafe { CStr::from_ptr(char_ptr) };
c_str.to_str()
}

Но нужно соблюсти 2 условия:
- сишная библиотека обязана не удалять строку
- сишная библиотека обязана не менять строку
Если соблюдение этих условий кажется проблематичным, то лучше сделать owned copy:
pub fn safe_fun() -> Result<String, Utf8Error> {
let char_ptr = unsafe { unsafe_fun() };
let c_str = unsafe { CStr::from_ptr(char_ptr) };
c_str.to_str().map(|s| s.to_owned())
}

BY Linker Unsafe


Share with your friend now:
tgoop.com/nlinker_rust/1832

View MORE
Open in Telegram


Telegram News

Date: |

Unlimited number of subscribers per channel Commenting about the court's concerns about the spread of false information related to the elections, Minister Fachin noted Brazil is "facing circumstances that could put Brazil's democracy at risk." During the meeting, the information technology secretary at the TSE, Julio Valente, put forward a list of requests the court believes will disinformation. To view your bio, click the Menu icon and select “View channel info.” Telegram Channels requirements & features In the next window, choose the type of your channel. If you want your channel to be public, you need to develop a link for it. In the screenshot below, it’s ”/catmarketing.” If your selected link is unavailable, you’ll need to suggest another option.
from us


Telegram Linker Unsafe
FROM American