Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pbjson-build/src/generator/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn write_field_empty_predicate<W: Write>(
| (FieldType::Scalar(ScalarType::Bytes), FieldModifier::UseDefault) => {
write!(writer, "!self.{}.is_empty()", member.rust_field_name())
}
(_, FieldModifier::Optional) | (FieldType::Message(_), _) => {
(_, FieldModifier::Optional) | (FieldType::Message, _) => {
write!(writer, "self.{}.is_some()", member.rust_field_name())
}
(FieldType::Scalar(ScalarType::F64), FieldModifier::UseDefault)
Expand Down Expand Up @@ -877,7 +877,7 @@ fn write_deserialize_field<W: Write>(
field.rust_type_name()
)?;
}
FieldType::Message(_) => writeln!(
FieldType::Message => writeln!(
writer,
"map_.next_value::<::std::option::Option<_>>()?.map({}::{})",
resolver.rust_type(&one_of.path),
Expand Down Expand Up @@ -983,7 +983,7 @@ fn write_deserialize_field<W: Write>(
}
write!(writer, "{})", Indent(indent + 1))?;
}
FieldType::Message(_) => match field.field_modifier {
FieldType::Message => match field.field_modifier {
FieldModifier::Repeated => {
// No explicit presence for repeated fields
write!(writer, "Some(map_.next_value()?)")?;
Expand Down
6 changes: 2 additions & 4 deletions pbjson-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
)]

use prost_types::FileDescriptorProto;
use std::io::{BufWriter, Error, ErrorKind, Result, Write};
use std::io::{BufWriter, Error, Result, Write};
use std::path::PathBuf;

use crate::descriptor::{Descriptor, Package};
Expand Down Expand Up @@ -205,9 +205,7 @@ impl Builder {
pub fn build<S: AsRef<str>>(&mut self, prefixes: &[S]) -> Result<()> {
let mut output: PathBuf = self.out_dir.clone().map(Ok).unwrap_or_else(|| {
std::env::var_os("OUT_DIR")
.ok_or_else(|| {
Error::new(ErrorKind::Other, "OUT_DIR environment variable is not set")
})
.ok_or_else(|| Error::other("OUT_DIR environment variable is not set"))
.map(Into::into)
})?;
output.push("FILENAME");
Expand Down
8 changes: 4 additions & 4 deletions pbjson-build/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl ScalarType {
pub enum FieldType {
Scalar(ScalarType),
Enum(TypePath),
Message(TypePath),
Message,
Map(ScalarType, Box<FieldType>),
}

Expand Down Expand Up @@ -203,7 +203,7 @@ fn field_modifier(
Label::Optional => match message.syntax {
Syntax::Proto2 => FieldModifier::Optional,
Syntax::Proto3 => match field_type {
FieldType::Message(_) => FieldModifier::Optional,
FieldType::Message => FieldModifier::Optional,
_ => FieldModifier::UseDefault,
},
},
Expand Down Expand Up @@ -245,7 +245,7 @@ fn resolve_type(descriptors: &DescriptorSet, type_name: &str) -> FieldType {

match maybe_descriptor {
Some((path, Descriptor::Enum(_))) => FieldType::Enum(path.clone()),
Some((path, Descriptor::Message(descriptor))) => match descriptor.is_map() {
Some((_path, Descriptor::Message(descriptor))) => match descriptor.is_map() {
true => {
assert_eq!(descriptor.fields.len(), 2, "expected map to have 2 fields");
let key = &descriptor.fields[0];
Expand All @@ -263,7 +263,7 @@ fn resolve_type(descriptors: &DescriptorSet, type_name: &str) -> FieldType {
}
// Note: This may actually be a group but it is non-trivial to detect this,
// they're deprecated, and pbjson doesn't need to be able to distinguish
false => FieldType::Message(path.clone()),
false => FieldType::Message,
},
None => panic!("failed to resolve type: {}", type_name),
}
Expand Down
Binary file modified pbjson-types/descriptors.bin
Binary file not shown.
8 changes: 5 additions & 3 deletions pbjson/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ pub mod private {
#[test]
fn test_bytes() {
for _ in 0..20 {
let mut rng = thread_rng();
let len = rng.gen_range(50..100);
let raw: Vec<_> = std::iter::from_fn(|| Some(rng.gen())).take(len).collect();
let mut rng = rand::rng();
let len = rng.random_range(50..100);
let raw: Vec<_> = std::iter::from_fn(|| Some(rng.random()))
.take(len)
.collect();

for config in [
base64::engine::general_purpose::STANDARD,
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.74"
channel = "1.91"
components = ["rustfmt", "clippy"]