/
githubmirror
/
servo
Обзор
Документация
Войти
/
githubmirror
/
servo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
components/shared/profile/generic_callback.rs
42 строки
1 KB
Euclid Ye
cargo: Rename workspace-local library starting with b to `servo_*` (#43552)
23 мар 2026, 11:26
Не верифицирован
23 мар 2026, 11:26
cae0752
Код
Авторство
О чём код?
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use malloc_size_of_derive::MallocSizeOf; use serde::{Deserialize, Serialize}; use servo_base::generic_channel::SendResult; use crate::time::{ProfilerCategory, ProfilerChan}; use crate::time_profile; #[derive(Clone, Debug, Serialize, Deserialize, MallocSizeOf)] pub struct GenericCallback<T> where T: Serialize + Send + 'static, { callback: servo_base::generic_channel::GenericCallback<T>, time_profiler_chan: ProfilerChan, } impl<T> GenericCallback<T> where T: for<'de> Deserialize<'de> + Serialize + Send + 'static, { pub fn new<F: FnMut(Result<T, ipc_channel::IpcError>) + Send + 'static>( time_profiler_chan: ProfilerChan, callback: F, ) -> Result<Self, ipc_channel::IpcError> { Ok(GenericCallback { callback: servo_base::generic_channel::GenericCallback::new(callback)?, time_profiler_chan, }) } pub fn send(&self, value: T) -> SendResult { time_profile!( ProfilerCategory::IpcReceiver, None, self.time_profiler_chan.clone(), move || self.callback.send(value) ) } }