mz_proto/
tokio_postgres.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
10use proptest::strategy::Strategy;
11use tokio_postgres::config::SslMode;
12
13use crate::{RustType, TryFromProtoError};
14
15include!(concat!(env!("OUT_DIR"), "/mz_proto.tokio_postgres.rs"));
16
17pub fn any_ssl_mode() -> impl Strategy<Value = SslMode> {
18    proptest::sample::select(vec![
19        SslMode::Disable,
20        SslMode::Prefer,
21        SslMode::Require,
22        SslMode::VerifyCa,
23        SslMode::VerifyFull,
24    ])
25}
26
27impl RustType<ProtoSslMode> for SslMode {
28    fn into_proto(&self) -> ProtoSslMode {
29        use proto_ssl_mode::Kind::*;
30        ProtoSslMode {
31            kind: Some(match self {
32                SslMode::Disable => Disable(()),
33                SslMode::Prefer => Prefer(()),
34                SslMode::Require => Require(()),
35                SslMode::VerifyCa => VerifyCa(()),
36                SslMode::VerifyFull => VerifyFull(()),
37                _ => Unknown(()),
38            }),
39        }
40    }
41
42    fn from_proto(proto: ProtoSslMode) -> Result<Self, TryFromProtoError> {
43        use proto_ssl_mode::Kind::*;
44        match proto.kind {
45            Some(Disable(())) => Ok(SslMode::Disable),
46            Some(Prefer(())) => Ok(SslMode::Prefer),
47            Some(Require(())) => Ok(SslMode::Require),
48            Some(VerifyCa(())) => Ok(SslMode::VerifyCa),
49            Some(VerifyFull(())) => Ok(SslMode::VerifyFull),
50            Some(Unknown(())) => Err(TryFromProtoError::unknown_enum_variant(
51                "ProtoSslMode::kind",
52            )),
53            None => Err(TryFromProtoError::missing_field("ProtoSslMode::kind")),
54        }
55    }
56}