Skip to main content

rocketmq_runtime/
task.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/// Service task types and operations.
16pub mod service_task;
17
18use std::pin::Pin;
19
20pub use service_task::ServiceManager;
21
22/// Allocates a box and then builds `make`'s value into it.
23///
24/// `Box::pin(make())` builds the value first, on the stack, and copies it into the allocation:
25/// for a future that copy is its whole type size, mostly the uninitialized space of states it
26/// has not reached. Allocating first gives the value a destination when it is built, so the
27/// optimizer can build it in the allocation directly; for a large future that saves copying
28/// kilobytes of unused state on every call.
29#[inline]
30pub fn box_in_place<T>(make: impl FnOnce() -> T) -> Pin<Box<T>> {
31    let slot = Box::new_uninit();
32    Box::into_pin(Box::write(slot, make()))
33}