typedb_driver/connection/
credentials.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20use std::fmt;
21
22/// User credentials for connecting to TypeDB
23#[derive(Clone)]
24pub struct Credentials {
25    username: String,
26    password: String,
27}
28
29/// User credentials for connecting to TypeDB
30impl Credentials {
31    /// Creates a credentials with username and password.
32    ///
33    /// # Arguments
34    ///
35    /// * `username` —  The name of the user to connect as
36    /// * `password` — The password for the user
37    ///
38    /// # Examples
39    ///
40    /// ```rust
41    /// Credentials::new(username, password);
42    ///```
43    pub fn new(username: &str, password: &str) -> Self {
44        Self { username: username.to_owned(), password: password.to_owned() }
45    }
46
47    /// Retrieves the username used.
48    pub fn username(&self) -> &str {
49        &self.username
50    }
51
52    /// Retrieves the password used.
53    pub fn password(&self) -> &str {
54        &self.password
55    }
56}
57
58impl fmt::Debug for Credentials {
59    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60        f.debug_struct("Credentials").field("username", &self.username).finish()
61    }
62}