Skip to content

Commit bb9d288

Browse files
authored
Replace .to_str_name() with .as_str_name() (#680)
1 parent ac57645 commit bb9d288

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

prost-build/src/code_generator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ impl<'a> CodeGenerator<'a> {
662662
);
663663
self.push_indent();
664664
self.buf
665-
.push_str("pub fn to_str_name(&self) -> &'static str {\n");
665+
.push_str("pub fn as_str_name(&self) -> &'static str {\n");
666666
self.depth += 1;
667667

668668
self.push_indent();
@@ -685,7 +685,7 @@ impl<'a> CodeGenerator<'a> {
685685

686686
self.depth -= 1;
687687
self.push_indent();
688-
self.buf.push_str("}\n"); // End of to_str_name()
688+
self.buf.push_str("}\n"); // End of as_str_name()
689689

690690
self.path.pop();
691691
self.depth -= 1;

prost-types/src/compiler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub mod code_generator_response {
141141
///
142142
/// The values are not transformed in any way and thus are considered stable
143143
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
144-
pub fn to_str_name(&self) -> &'static str {
144+
pub fn as_str_name(&self) -> &'static str {
145145
match self {
146146
Feature::None => "FEATURE_NONE",
147147
Feature::Proto3Optional => "FEATURE_PROTO3_OPTIONAL",

prost-types/src/protobuf.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub mod field_descriptor_proto {
214214
///
215215
/// The values are not transformed in any way and thus are considered stable
216216
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
217-
pub fn to_str_name(&self) -> &'static str {
217+
pub fn as_str_name(&self) -> &'static str {
218218
match self {
219219
Type::Double => "TYPE_DOUBLE",
220220
Type::Float => "TYPE_FLOAT",
@@ -250,7 +250,7 @@ pub mod field_descriptor_proto {
250250
///
251251
/// The values are not transformed in any way and thus are considered stable
252252
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
253-
pub fn to_str_name(&self) -> &'static str {
253+
pub fn as_str_name(&self) -> &'static str {
254254
match self {
255255
Label::Optional => "LABEL_OPTIONAL",
256256
Label::Required => "LABEL_REQUIRED",
@@ -507,7 +507,7 @@ pub mod file_options {
507507
///
508508
/// The values are not transformed in any way and thus are considered stable
509509
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
510-
pub fn to_str_name(&self) -> &'static str {
510+
pub fn as_str_name(&self) -> &'static str {
511511
match self {
512512
OptimizeMode::Speed => "SPEED",
513513
OptimizeMode::CodeSize => "CODE_SIZE",
@@ -661,7 +661,7 @@ pub mod field_options {
661661
///
662662
/// The values are not transformed in any way and thus are considered stable
663663
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
664-
pub fn to_str_name(&self) -> &'static str {
664+
pub fn as_str_name(&self) -> &'static str {
665665
match self {
666666
CType::String => "STRING",
667667
CType::Cord => "CORD",
@@ -684,7 +684,7 @@ pub mod field_options {
684684
///
685685
/// The values are not transformed in any way and thus are considered stable
686686
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
687-
pub fn to_str_name(&self) -> &'static str {
687+
pub fn as_str_name(&self) -> &'static str {
688688
match self {
689689
JsType::JsNormal => "JS_NORMAL",
690690
JsType::JsString => "JS_STRING",
@@ -782,7 +782,7 @@ pub mod method_options {
782782
///
783783
/// The values are not transformed in any way and thus are considered stable
784784
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
785-
pub fn to_str_name(&self) -> &'static str {
785+
pub fn as_str_name(&self) -> &'static str {
786786
match self {
787787
IdempotencyLevel::IdempotencyUnknown => "IDEMPOTENCY_UNKNOWN",
788788
IdempotencyLevel::NoSideEffects => "NO_SIDE_EFFECTS",
@@ -1253,7 +1253,7 @@ pub mod field {
12531253
///
12541254
/// The values are not transformed in any way and thus are considered stable
12551255
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
1256-
pub fn to_str_name(&self) -> &'static str {
1256+
pub fn as_str_name(&self) -> &'static str {
12571257
match self {
12581258
Kind::TypeUnknown => "TYPE_UNKNOWN",
12591259
Kind::TypeDouble => "TYPE_DOUBLE",
@@ -1295,7 +1295,7 @@ pub mod field {
12951295
///
12961296
/// The values are not transformed in any way and thus are considered stable
12971297
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
1298-
pub fn to_str_name(&self) -> &'static str {
1298+
pub fn as_str_name(&self) -> &'static str {
12991299
match self {
13001300
Cardinality::Unknown => "CARDINALITY_UNKNOWN",
13011301
Cardinality::Optional => "CARDINALITY_OPTIONAL",
@@ -1368,7 +1368,7 @@ impl Syntax {
13681368
///
13691369
/// The values are not transformed in any way and thus are considered stable
13701370
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
1371-
pub fn to_str_name(&self) -> &'static str {
1371+
pub fn as_str_name(&self) -> &'static str {
13721372
match self {
13731373
Syntax::Proto2 => "SYNTAX_PROTO2",
13741374
Syntax::Proto3 => "SYNTAX_PROTO3",
@@ -1934,7 +1934,7 @@ impl NullValue {
19341934
///
19351935
/// The values are not transformed in any way and thus are considered stable
19361936
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
1937-
pub fn to_str_name(&self) -> &'static str {
1937+
pub fn as_str_name(&self) -> &'static str {
19381938
match self {
19391939
NullValue::NullValue => "NULL_VALUE",
19401940
}

tests/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,19 +533,19 @@ mod tests {
533533
fn test_enum_to_string() {
534534
use default_enum_value::{ERemoteClientBroadcastMsg, PrivacyLevel};
535535

536-
assert_eq!(PrivacyLevel::One.to_str_name(), "PRIVACY_LEVEL_ONE");
537-
assert_eq!(PrivacyLevel::Two.to_str_name(), "PRIVACY_LEVEL_TWO");
536+
assert_eq!(PrivacyLevel::One.as_str_name(), "PRIVACY_LEVEL_ONE");
537+
assert_eq!(PrivacyLevel::Two.as_str_name(), "PRIVACY_LEVEL_TWO");
538538
assert_eq!(
539-
PrivacyLevel::PrivacyLevelThree.to_str_name(),
539+
PrivacyLevel::PrivacyLevelThree.as_str_name(),
540540
"PRIVACY_LEVEL_PRIVACY_LEVEL_THREE"
541541
);
542542
assert_eq!(
543-
PrivacyLevel::PrivacyLevelprivacyLevelFour.to_str_name(),
543+
PrivacyLevel::PrivacyLevelprivacyLevelFour.as_str_name(),
544544
"PRIVACY_LEVELPRIVACY_LEVEL_FOUR"
545545
);
546546

547547
assert_eq!(
548-
ERemoteClientBroadcastMsg::KERemoteClientBroadcastMsgDiscovery.to_str_name(),
548+
ERemoteClientBroadcastMsg::KERemoteClientBroadcastMsgDiscovery.as_str_name(),
549549
"k_ERemoteClientBroadcastMsgDiscovery"
550550
);
551551
}

0 commit comments

Comments
 (0)