phonenumber_fixed/
extension.rs

1// Copyright (C) 2017 1aim GmbH
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
15use std::ops::Deref;
16use std::fmt;
17
18/// A phone number extension.
19#[derive(Clone, Eq, PartialEq, Serialize, Deserialize, Hash, Debug)]
20pub struct Extension(pub(crate) String);
21
22impl<T: Into<String>> From<T> for Extension {
23	fn from(value: T) -> Extension {
24		Extension(value.into())
25	}
26}
27
28impl Deref for Extension {
29	type Target = str;
30
31	fn deref(&self) -> &str {
32		&self.0
33	}
34}
35
36impl AsRef<str> for Extension {
37	fn as_ref(&self) -> &str {
38		&self.0
39	}
40}
41
42impl fmt::Display for Extension {
43	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44		write!(f, "{}", self.0)
45	}
46}