mz_repr/adt/pg_legacy_name.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/// The number of bytes required **by PostgreSQL** to store a value of type
11/// [`ScalarType::PgLegacyName`](crate::ScalarType::PgLegacyName).
12///
13/// Corresponds to the `NAMEDATALEN` constant in the PostgreSQL source code.
14///
15/// Note that the length contains an extra byte for the null terminator. This
16/// does not directly correspond to Materialize, as Rust `String`s do not use
17/// a null terminator. You should generally use `NAME_MAX_BYTES` instead, which
18/// describes the maximum number of usable bytes in a `name` value.
19const PG_NAMEDATALEN: usize = 64;
20
21/// The maximum number of bytes that may be stored in a value of type
22/// [`ScalarType::PgLegacyName`](crate::ScalarType::PgLegacyName).
23pub const NAME_MAX_BYTES: usize = PG_NAMEDATALEN - 1;
24
25/// A Rust type representing a PostgreSQL `name` type.
26#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
27pub struct PgLegacyName<S>(pub S)
28where
29 S: AsRef<str>;