LEARN_RUST_UKR Telegram 251
Rust порада, яка вам точно не треба ⤵️

Якщо ви часто використовуєте Windows API, можливо Owned тип із windows::core модуля це саме те, чого вам не вистачало.
Дуже легко забути закрити (вивільнити) handle. Якщо ви обгорнете його Owned типом, то він автоматично закриється під час видалення об'єкта (on drop).
use windows::Win32::System::Services::SC_HANDLE;
use windows::code::Owned;

pub struct MyService {
service_handle: Owned<SC_HANDLE>,
}

MyService {
service_handle: unsafe { Owned::new(OpenSCManagerW(/* ... */)?) },
}

Owned тип можна використовувати із кожним типом із windows крейту, який імплементує Free трейт. По-суті, це будь який handle.
Please open Telegram to view this post
VIEW IN TELEGRAM
👍10🔥4👏2



tgoop.com/learn_rust_ukr/251
Create:
Last Update:

Rust порада, яка вам точно не треба ⤵️

Якщо ви часто використовуєте Windows API, можливо Owned тип із windows::core модуля це саме те, чого вам не вистачало.
Дуже легко забути закрити (вивільнити) handle. Якщо ви обгорнете його Owned типом, то він автоматично закриється під час видалення об'єкта (on drop).

use windows::Win32::System::Services::SC_HANDLE;
use windows::code::Owned;

pub struct MyService {
service_handle: Owned<SC_HANDLE>,
}

MyService {
service_handle: unsafe { Owned::new(OpenSCManagerW(/* ... */)?) },
}

Owned тип можна використовувати із кожним типом із windows крейту, який імплементує Free трейт. По-суті, це будь який handle.

BY Українська Rust Спільнота


Share with your friend now:
tgoop.com/learn_rust_ukr/251

View MORE
Open in Telegram


Telegram News

Date: |

Informative Telegram has announced a number of measures aiming to tackle the spread of disinformation through its platform in Brazil. These features are part of an agreement between the platform and the country's authorities ahead of the elections in October. A few years ago, you had to use a special bot to run a poll on Telegram. Now you can easily do that yourself in two clicks. Hit the Menu icon and select “Create Poll.” Write your question and add up to 10 options. Running polls is a powerful strategy for getting feedback from your audience. If you’re considering the possibility of modifying your channel in any way, be sure to ask your subscribers’ opinions first. Those being doxxed include outgoing Chief Executive Carrie Lam Cheng Yuet-ngor, Chung and police assistant commissioner Joe Chan Tung, who heads police's cyber security and technology crime bureau. Some Telegram Channels content management tips
from us


Telegram Українська Rust Спільнота
FROM American