Skip to content

Commit 6254b6a

Browse files
authored
Bump Rust version and run clippy/fmt (#526)
1 parent 7458a63 commit 6254b6a

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

gel-config/src/lib.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub mod validation;
66

77
use derive_more::{Display, Error};
88
use indexmap::IndexMap;
9-
use std::{borrow::Cow, fmt::Debug};
9+
use std::{borrow::Cow, fmt::Debug, str::FromStr};
1010
use toml::Value as TomlValue;
1111

1212
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -34,18 +34,21 @@ impl PrimitiveType {
3434
PrimitiveType::Duration => "duration",
3535
}
3636
}
37+
}
3738

38-
pub fn from_str(s: &str) -> Option<Self> {
39+
impl FromStr for PrimitiveType {
40+
type Err = ();
41+
fn from_str(s: &str) -> Result<Self, Self::Err> {
3942
match s {
40-
"str" => Some(PrimitiveType::String),
41-
"int64" => Some(PrimitiveType::Int64),
42-
"int32" => Some(PrimitiveType::Int32),
43-
"int16" => Some(PrimitiveType::Int16),
44-
"float64" => Some(PrimitiveType::Float64),
45-
"float32" => Some(PrimitiveType::Float32),
46-
"bool" => Some(PrimitiveType::Boolean),
47-
"duration" => Some(PrimitiveType::Duration),
48-
_ => None,
43+
"str" => Ok(PrimitiveType::String),
44+
"int64" => Ok(PrimitiveType::Int64),
45+
"int32" => Ok(PrimitiveType::Int32),
46+
"int16" => Ok(PrimitiveType::Int16),
47+
"float64" => Ok(PrimitiveType::Float64),
48+
"float32" => Ok(PrimitiveType::Float32),
49+
"bool" => Ok(PrimitiveType::Boolean),
50+
"duration" => Ok(PrimitiveType::Duration),
51+
_ => Err(()),
4952
}
5053
}
5154
}
@@ -70,11 +73,11 @@ pub enum Value {
7073
impl Debug for Value {
7174
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7275
match self {
73-
Value::Injected(s) => write!(f, "{}", s),
76+
Value::Injected(s) => write!(f, "{s}"),
7477
Value::Set(values) => {
7578
write!(f, "[")?;
7679
for (i, value) in values.iter().enumerate() {
77-
write!(f, "{:?}", value)?;
80+
write!(f, "{value:?}")?;
7881
if i < values.len() - 1 {
7982
write!(f, ", ")?;
8083
}
@@ -84,17 +87,17 @@ impl Debug for Value {
8487
Value::Array(values) => {
8588
write!(f, "[")?;
8689
for (i, value) in values.iter().enumerate() {
87-
write!(f, "{:?}", value)?;
90+
write!(f, "{value:?}")?;
8891
if i < values.len() - 1 {
8992
write!(f, ", ")?;
9093
}
9194
}
9295
write!(f, "]")
9396
}
9497
Value::Insert { typ, values } => {
95-
write!(f, "insert {} = {{\n", typ)?;
98+
writeln!(f, "insert {typ} = {{")?;
9699
for (key, value) in values {
97-
write!(f, " {}: {:?},\n", key, value)?;
100+
writeln!(f, " {key}: {value:?},")?;
98101
}
99102
write!(f, "}}")
100103
}

gel-config/src/validation.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct ConfigureSet {
2929
impl Debug for ConfigureSet {
3030
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3131
if let Some(extension_name) = &self.extension_name {
32-
write!(f, "configure {}", extension_name)?;
32+
write!(f, "configure {extension_name}")?;
3333
} else {
3434
write!(f, "configure")?;
3535
}
@@ -56,22 +56,22 @@ pub struct Commands {
5656
impl Debug for Commands {
5757
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5858
for set in &self.set {
59-
write!(f, "{:?};\n", set)?;
59+
writeln!(f, "{set:?};")?;
6060
}
6161
for (object_name, insert) in &self.insert {
6262
for value in &insert.values {
6363
if let Some(extension_name) = &insert.extension_name {
64-
write!(f, "insert {}", extension_name)?;
64+
write!(f, "insert {extension_name}")?;
6565
} else {
6666
write!(f, "insert")?;
6767
}
68-
write!(f, " {object_name} {{\n")?;
68+
writeln!(f, " {object_name} {{")?;
6969
for (key, value) in value {
7070
let mut value = format!("{value:?}");
7171
value = value.replace("\n", "\n ");
72-
write!(f, " {key}: {value},\n", key = key, value = value)?;
72+
writeln!(f, " {key}: {value},")?;
7373
}
74-
write!(f, "}};\n")?;
74+
writeln!(f, "}};")?;
7575
}
7676
}
7777
Ok(())

gel-config/tests/test_client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ fn test_complex() {
99
let toml = toml::Table::deserialize(toml).unwrap();
1010
let branch = toml.get("branch").unwrap().get("config").unwrap();
1111
let commands = validate(branch.clone(), &schema).unwrap();
12-
println!("branch:\n{:?}", commands);
12+
println!("branch:\n{commands:?}");
1313
let instance = toml.get("instance").unwrap().get("config").unwrap();
1414
let commands = validate(instance.clone(), &schema).unwrap();
15-
println!("instance:\n{:?}", commands);
15+
println!("instance:\n{commands:?}");
1616
}
1717

1818
#[test]
@@ -23,10 +23,10 @@ fn test_full() {
2323
let toml = toml::Table::deserialize(toml).unwrap();
2424
let branch = toml.get("branch").unwrap().get("config").unwrap();
2525
let commands = validate(branch.clone(), &schema).unwrap();
26-
println!("branch:\n{:?}", commands);
26+
println!("branch:\n{commands:?}");
2727
let instance = toml.get("instance").unwrap().get("config").unwrap();
2828
let commands = validate(instance.clone(), &schema).unwrap();
29-
println!("instance:\n{:?}", commands);
29+
println!("instance:\n{commands:?}");
3030
}
3131

3232
#[test]
@@ -37,5 +37,5 @@ fn test_object() {
3737
let toml = toml::Table::deserialize(toml).unwrap();
3838
let branch = toml.get("branch").unwrap().get("config").unwrap();
3939
let commands = validate(branch.clone(), &schema).unwrap();
40-
println!("{:?}", commands);
40+
println!("{commands:?}");
4141
}

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.85"
2+
channel = "1.88"
33
components = ["rustc", "cargo", "rust-std", "rust-src", "clippy", "rustfmt", "rust-analyzer"]

0 commit comments

Comments
 (0)