Skip to content

Commit

Permalink
Clippy suggestions RE: variant name prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton committed Dec 26, 2024
1 parent 158c3ae commit 0e53e48
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
1 change: 0 additions & 1 deletion src/lazy/any_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,6 @@ pub struct LazyRawAnyValue<'top> {

impl<'top> LazyRawAnyValue<'top> {
/// Returns an enum indicating the encoding that backs this lazy value.
#[cfg(feature = "experimental-tooling-apis")]
pub fn kind(&self) -> LazyRawValueKind<'top> {
self.encoding
}
Expand Down
2 changes: 1 addition & 1 deletion src/lazy/encoder/binary/v1_1/value_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl BinaryValueWriter_1_1<'_, '_> {
pub fn with_inline_symbol_text(mut self) -> Self {
self.value_writer_config = self
.value_writer_config
.with_symbol_value_encoding(SymbolValueEncoding::WriteAsInlineText);
.with_symbol_value_encoding(SymbolValueEncoding::InlineText);
self
}

Expand Down
31 changes: 16 additions & 15 deletions src/lazy/encoder/value_writer_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ pub enum ContainerEncoding {
pub enum SymbolValueEncoding {
/// Add all symbol values to the symbol table and encode them as symbol IDs.
#[default]
WriteAsSymbolIds,
SymbolIds,
/// Do not add symbol values to the symbol table; write their text inline.
/// Symbol values specified as symbol IDs will not be mapped to text.
WriteAsInlineText,
InlineText,
/// If a symbol value is already in the symbol table, encode it as a symbol ID.
/// If it is not already in the symbol table, encode its text inline.
WriteNewSymbolsAsInlineText,
NewSymbolsAsInlineText,
}

/// Configuration options for encoding an annotations sequence.
Expand All @@ -53,48 +53,49 @@ pub enum SymbolValueEncoding {
pub enum AnnotationsEncoding {
/// Add all annotations to the symbol table and encode them as symbol IDs.
#[default]
WriteAsSymbolIds,
SymbolIds,
/// Do not add annotations to the symbol table; write their text inline.
/// Annotations specified as symbol IDs will not be mapped to text.
WriteAsInlineText,
InlineText,
/// If an annotation is already in the symbol table, encode it as a symbol ID.
/// If it is not already in the symbol table, encode its text inline.
WriteNewSymbolsAsInlineText,
NewSymbolsAsInlineText,
}

/// Configuration options for encoding a struct field name.
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
#[non_exhaustive]
#[allow(clippy::enum_variant_names)]
pub enum FieldNameEncoding {
/// Add all field names to the symbol table and encode them as symbol IDs.
#[default]
WriteAsSymbolIds,
SymbolIds,
/// Do not add field names to the symbol table; write their text inline.
/// Field names specified as symbol IDs will not be mapped to text.
WriteAsInlineText,
InlineText,
/// If a field name is already in the symbol table, encode it as a symbol ID.
/// If it is not already in the symbol table, encode its text inline.
WriteNewSymbolsAsInlineText,
NewSymbolsAsInlineText,
}

impl ValueWriterConfig {
/// Constructs a `ValueWriterConfig` that writes all symbol tokens as inline text.
pub const fn text() -> Self {
ValueWriterConfig {
container_encoding: ContainerEncoding::Delimited,
symbol_value_encoding: SymbolValueEncoding::WriteAsInlineText,
annotations_encoding: AnnotationsEncoding::WriteAsInlineText,
field_name_encoding: FieldNameEncoding::WriteAsInlineText,
symbol_value_encoding: SymbolValueEncoding::InlineText,
annotations_encoding: AnnotationsEncoding::InlineText,
field_name_encoding: FieldNameEncoding::InlineText,
}
}

/// Constructs a `ValueWriterConfig` that writes all symbol tokens as symbol IDs.
pub const fn binary() -> Self {
ValueWriterConfig {
container_encoding: ContainerEncoding::LengthPrefixed,
symbol_value_encoding: SymbolValueEncoding::WriteAsSymbolIds,
annotations_encoding: AnnotationsEncoding::WriteAsSymbolIds,
field_name_encoding: FieldNameEncoding::WriteAsSymbolIds,
symbol_value_encoding: SymbolValueEncoding::SymbolIds,
annotations_encoding: AnnotationsEncoding::SymbolIds,
field_name_encoding: FieldNameEncoding::SymbolIds,
}
}

Expand Down
34 changes: 17 additions & 17 deletions src/lazy/encoder/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,15 @@ impl<V: ValueWriter> AnnotatableWriter for ApplicationValueWriter<'_, V> {
{
let mut annotations = annotations.into_annotations_vec();
match self.value_writer_config.annotations_encoding() {
AnnotationsEncoding::WriteAsSymbolIds => {
AnnotationsEncoding::SymbolIds => {
// Intern all text so everything we write is a symbol ID
self.intern_all_annotations(&mut annotations)?
}
AnnotationsEncoding::WriteAsInlineText => {
AnnotationsEncoding::InlineText => {
// Validate the symbol IDs, write the text as-is
self.validate_all_symbol_ids(&mut annotations)?
}
AnnotationsEncoding::WriteNewSymbolsAsInlineText => {
AnnotationsEncoding::NewSymbolsAsInlineText => {
// Map all known strings to symbol IDs, leave new text as is.
self.map_known_symbols_to_symbol_ids(&mut annotations)?
}
Expand Down Expand Up @@ -476,7 +476,7 @@ impl<'value, V: ValueWriter> ValueWriter for ApplicationValueWriter<'value, V> {
SystemSymbol_1_1(symbol) => SystemSymbol_1_1(symbol),
Text(text) => {
match value_writer_config.symbol_value_encoding() {
WriteAsSymbolIds => {
SymbolIds => {
// Map the text to a symbol ID.
match encoding.symbol_table.sid_for(text) {
// If it's already in the symbol table, use that SID.
Expand All @@ -488,15 +488,15 @@ impl<'value, V: ValueWriter> ValueWriter for ApplicationValueWriter<'value, V> {
}
}
}
WriteNewSymbolsAsInlineText => {
NewSymbolsAsInlineText => {
// If the text is in the symbol table, use the symbol ID. Otherwise, use the text itself.
match encoding.symbol_table.sid_for(text) {
Some(symbol_id) => SymbolId(symbol_id),
None => Text(text),
}
}
// We have text and we want to write text. Nothing to do.
WriteAsInlineText => Text(text),
InlineText => Text(text),
}
}
};
Expand Down Expand Up @@ -609,7 +609,7 @@ impl<V: ValueWriter> FieldEncoder for ApplicationStructWriter<'_, V> {
// From here on, we're dealing with text.

// If the struct writer is configured to write field names as text, do that.
if self.value_writer_config.field_name_encoding() == FieldNameEncoding::WriteAsInlineText {
if self.value_writer_config.field_name_encoding() == FieldNameEncoding::InlineText {
return self.raw_struct_writer.encode_field_name(text);
}

Expand All @@ -620,7 +620,7 @@ impl<V: ValueWriter> FieldEncoder for ApplicationStructWriter<'_, V> {
// If it's not but the struct writer is configured to intern new text, add it to the
// symbol table.
None if self.value_writer_config.field_name_encoding()
== FieldNameEncoding::WriteAsSymbolIds =>
== FieldNameEncoding::SymbolIds =>
{
self.encoding.num_pending_symbols += 1;
self.encoding.symbol_table.add_symbol_for_text(text).into()
Expand Down Expand Up @@ -852,7 +852,7 @@ mod tests {
fn intern_new_symbol_values() -> IonResult<()> {
use RawSymbolRef::*;
symbol_value_encoding_test(
SymbolValueEncoding::WriteAsSymbolIds,
SymbolValueEncoding::SymbolIds,
[
(Text("$ion_symbol_table"), &[0xE1, 0x03]),
(Text("name"), &[0xE1, 0x04]),
Expand All @@ -866,7 +866,7 @@ mod tests {
fn do_not_intern_new_symbol_values() -> IonResult<()> {
use RawSymbolRef::*;
symbol_value_encoding_test(
SymbolValueEncoding::WriteNewSymbolsAsInlineText,
SymbolValueEncoding::NewSymbolsAsInlineText,
[
// Known text symbols are written as SIDs
(Text("$ion_symbol_table"), &[0xE1, 0x03]),
Expand All @@ -884,7 +884,7 @@ mod tests {
fn encode_all_text_as_is() -> IonResult<()> {
use RawSymbolRef::*;
symbol_value_encoding_test(
SymbolValueEncoding::WriteAsInlineText,
SymbolValueEncoding::InlineText,
[
// Known text symbols are written as inline text
(Text("name"), &[0xA4, 0x6E, 0x61, 0x6D, 0x65]),
Expand Down Expand Up @@ -927,7 +927,7 @@ mod tests {
fn intern_new_annotations() -> IonResult<()> {
use RawSymbolRef::*;
annotations_sequence_encoding_test(
AnnotationsEncoding::WriteAsSymbolIds,
AnnotationsEncoding::SymbolIds,
&[
Text("$ion_symbol_table"),
Text("name"),
Expand All @@ -949,7 +949,7 @@ mod tests {
fn write_new_annotations_as_text() -> IonResult<()> {
use RawSymbolRef::*;
annotations_sequence_encoding_test(
AnnotationsEncoding::WriteNewSymbolsAsInlineText,
AnnotationsEncoding::NewSymbolsAsInlineText,
&[
Text("$ion_symbol_table"),
Text("name"),
Expand All @@ -974,7 +974,7 @@ mod tests {
fn write_text_annotations_as_is() -> IonResult<()> {
use RawSymbolRef::*;
annotations_sequence_encoding_test(
AnnotationsEncoding::WriteAsInlineText,
AnnotationsEncoding::InlineText,
&[Text("name"), SymbolId(6), Text("foo")],
&[
0xE9, // Opcode: FlexUInt follows with byte length of sequence
Expand Down Expand Up @@ -1031,7 +1031,7 @@ mod tests {
#[test]
fn intern_all_field_names() -> IonResult<()> {
struct_field_encoding_test(
FieldNameEncoding::WriteAsSymbolIds,
FieldNameEncoding::SymbolIds,
&[
// New symbols
(RawSymbolRef::Text("foo"), &[0x81]), // FlexUInt SID $64,
Expand All @@ -1047,7 +1047,7 @@ mod tests {
#[test]
fn write_all_field_names_as_text() -> IonResult<()> {
struct_field_encoding_test(
FieldNameEncoding::WriteAsInlineText,
FieldNameEncoding::InlineText,
&[
// New symbols
(RawSymbolRef::Text("foo"), &[0xFB, 0x66, 0x6F, 0x6F]), // FlexSym -3, "foo"
Expand All @@ -1062,7 +1062,7 @@ mod tests {
#[test]
fn write_new_field_names_as_text() -> IonResult<()> {
struct_field_encoding_test(
FieldNameEncoding::WriteNewSymbolsAsInlineText,
FieldNameEncoding::NewSymbolsAsInlineText,
&[
// New symbols
(RawSymbolRef::Text("foo"), &[0xFB, 0x66, 0x6F, 0x6F]), // FlexSym -3, "foo"
Expand Down
12 changes: 6 additions & 6 deletions src/lazy/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ impl Encoding for BinaryEncoding_1_0 {

fn default_value_writer_config() -> ValueWriterConfig {
ValueWriterConfig::binary()
.with_field_name_encoding(FieldNameEncoding::WriteAsSymbolIds)
.with_annotations_encoding(AnnotationsEncoding::WriteAsSymbolIds)
.with_field_name_encoding(FieldNameEncoding::SymbolIds)
.with_annotations_encoding(AnnotationsEncoding::SymbolIds)
.with_container_encoding(ContainerEncoding::LengthPrefixed)
.with_symbol_value_encoding(SymbolValueEncoding::WriteAsSymbolIds)
.with_symbol_value_encoding(SymbolValueEncoding::SymbolIds)
}
}
impl Encoding for BinaryEncoding_1_1 {
Expand Down Expand Up @@ -206,10 +206,10 @@ impl Encoding for TextEncoding_1_0 {
}
fn default_value_writer_config() -> ValueWriterConfig {
ValueWriterConfig::text()
.with_field_name_encoding(FieldNameEncoding::WriteAsInlineText)
.with_annotations_encoding(AnnotationsEncoding::WriteAsInlineText)
.with_field_name_encoding(FieldNameEncoding::InlineText)
.with_annotations_encoding(AnnotationsEncoding::InlineText)
.with_container_encoding(ContainerEncoding::Delimited)
.with_symbol_value_encoding(SymbolValueEncoding::WriteAsInlineText)
.with_symbol_value_encoding(SymbolValueEncoding::InlineText)
}
}
impl Encoding for TextEncoding_1_1 {
Expand Down

0 comments on commit 0e53e48

Please sign in to comment.