proto_types/protovalidate/
mod.rs1#![allow(clippy::len_without_is_empty, clippy::too_long_first_doc_paragraph)]
2include!("./buf.validate.rs");
3
4use crate::protovalidate::field_path_element::Subscript;
5
6mod violations;
7
8use crate::{Display, String, ToString, fmt};
9
10pub use violations::*;
11
12impl From<usize> for Subscript {
13 fn from(value: usize) -> Self {
14 Self::Index(value as u64)
15 }
16}
17
18impl From<i64> for Subscript {
19 fn from(value: i64) -> Self {
20 Self::IntKey(value)
21 }
22}
23
24impl From<i32> for Subscript {
25 fn from(value: i32) -> Self {
26 Self::IntKey(value.into())
27 }
28}
29
30impl From<u64> for Subscript {
31 fn from(value: u64) -> Self {
32 Self::UintKey(value)
33 }
34}
35
36impl From<u32> for Subscript {
37 fn from(value: u32) -> Self {
38 Self::UintKey(value.into())
39 }
40}
41
42impl From<bool> for Subscript {
43 fn from(value: bool) -> Self {
44 Self::BoolKey(value)
45 }
46}
47
48impl From<String> for Subscript {
49 fn from(value: String) -> Self {
50 Self::StringKey(value)
51 }
52}
53
54impl From<&str> for Subscript {
55 fn from(value: &str) -> Self {
56 Self::StringKey(value.to_string())
57 }
58}
59
60impl Display for Subscript {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 match self {
63 Self::BoolKey(val) => write!(f, "{val}"),
64 Self::IntKey(val) => write!(f, "{val}"),
65 Self::Index(val) | Self::UintKey(val) => write!(f, "{val}"),
66 Self::StringKey(val) => write!(f, "{val}"),
67 }
68 }
69}