mz_catalog/durable/
traits.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10/// A copy of [`std::convert::From`] so we can work around Rust's orphan rules.
11///
12/// The protobuf objects we durably persist for the catalog live in the
13/// [`mz_catalog_protos`] crate, because [`prost`]s heavy usage of proc-macros
14/// results in very long compile times. By moving them into a separate crate we
15/// need to recompile them a lot less frequently.
16pub(crate) trait UpgradeFrom<T>: Sized {
17    fn upgrade_from(value: T) -> Self;
18}
19
20impl<T, U> UpgradeInto<U> for T
21where
22    U: UpgradeFrom<T>,
23{
24    fn upgrade_into(self) -> U {
25        U::upgrade_from(self)
26    }
27}
28
29/// A copy of [`std::convert::Into`] so we can work around Rust's orphan rules.
30pub(crate) trait UpgradeInto<U>: Sized {
31    fn upgrade_into(self) -> U;
32}