Skip to content

Commit

Permalink
Replace .to_str_name() with .as_str_name() (#680)
Browse files Browse the repository at this point in the history
  • Loading branch information
vriesk authored Jul 6, 2022
1 parent ac57645 commit bb9d288
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions prost-build/src/code_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ impl<'a> CodeGenerator<'a> {
);
self.push_indent();
self.buf
.push_str("pub fn to_str_name(&self) -> &'static str {\n");
.push_str("pub fn as_str_name(&self) -> &'static str {\n");
self.depth += 1;

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

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

self.path.pop();
self.depth -= 1;
Expand Down
2 changes: 1 addition & 1 deletion prost-types/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub mod code_generator_response {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn to_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
Feature::None => "FEATURE_NONE",
Feature::Proto3Optional => "FEATURE_PROTO3_OPTIONAL",
Expand Down
20 changes: 10 additions & 10 deletions prost-types/src/protobuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ pub mod field_descriptor_proto {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn to_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
Type::Double => "TYPE_DOUBLE",
Type::Float => "TYPE_FLOAT",
Expand Down Expand Up @@ -250,7 +250,7 @@ pub mod field_descriptor_proto {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn to_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
Label::Optional => "LABEL_OPTIONAL",
Label::Required => "LABEL_REQUIRED",
Expand Down Expand Up @@ -507,7 +507,7 @@ pub mod file_options {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn to_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
OptimizeMode::Speed => "SPEED",
OptimizeMode::CodeSize => "CODE_SIZE",
Expand Down Expand Up @@ -661,7 +661,7 @@ pub mod field_options {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn to_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
CType::String => "STRING",
CType::Cord => "CORD",
Expand All @@ -684,7 +684,7 @@ pub mod field_options {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn to_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
JsType::JsNormal => "JS_NORMAL",
JsType::JsString => "JS_STRING",
Expand Down Expand Up @@ -782,7 +782,7 @@ pub mod method_options {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn to_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
IdempotencyLevel::IdempotencyUnknown => "IDEMPOTENCY_UNKNOWN",
IdempotencyLevel::NoSideEffects => "NO_SIDE_EFFECTS",
Expand Down Expand Up @@ -1253,7 +1253,7 @@ pub mod field {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn to_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
Kind::TypeUnknown => "TYPE_UNKNOWN",
Kind::TypeDouble => "TYPE_DOUBLE",
Expand Down Expand Up @@ -1295,7 +1295,7 @@ pub mod field {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn to_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
Cardinality::Unknown => "CARDINALITY_UNKNOWN",
Cardinality::Optional => "CARDINALITY_OPTIONAL",
Expand Down Expand Up @@ -1368,7 +1368,7 @@ impl Syntax {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn to_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
Syntax::Proto2 => "SYNTAX_PROTO2",
Syntax::Proto3 => "SYNTAX_PROTO3",
Expand Down Expand Up @@ -1934,7 +1934,7 @@ impl NullValue {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn to_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
NullValue::NullValue => "NULL_VALUE",
}
Expand Down
10 changes: 5 additions & 5 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,19 +533,19 @@ mod tests {
fn test_enum_to_string() {
use default_enum_value::{ERemoteClientBroadcastMsg, PrivacyLevel};

assert_eq!(PrivacyLevel::One.to_str_name(), "PRIVACY_LEVEL_ONE");
assert_eq!(PrivacyLevel::Two.to_str_name(), "PRIVACY_LEVEL_TWO");
assert_eq!(PrivacyLevel::One.as_str_name(), "PRIVACY_LEVEL_ONE");
assert_eq!(PrivacyLevel::Two.as_str_name(), "PRIVACY_LEVEL_TWO");
assert_eq!(
PrivacyLevel::PrivacyLevelThree.to_str_name(),
PrivacyLevel::PrivacyLevelThree.as_str_name(),
"PRIVACY_LEVEL_PRIVACY_LEVEL_THREE"
);
assert_eq!(
PrivacyLevel::PrivacyLevelprivacyLevelFour.to_str_name(),
PrivacyLevel::PrivacyLevelprivacyLevelFour.as_str_name(),
"PRIVACY_LEVELPRIVACY_LEVEL_FOUR"
);

assert_eq!(
ERemoteClientBroadcastMsg::KERemoteClientBroadcastMsgDiscovery.to_str_name(),
ERemoteClientBroadcastMsg::KERemoteClientBroadcastMsgDiscovery.as_str_name(),
"k_ERemoteClientBroadcastMsgDiscovery"
);
}
Expand Down

0 comments on commit bb9d288

Please sign in to comment.