Skip to content
Snippets Groups Projects
Verified Commit 1750001b authored by Yaroslav Dynnikov's avatar Yaroslav Dynnikov
Browse files

refactoring: uniform string conversion

1. Prefer using `"str".into()` since it's briefer.
2. Preserve `"str".to_owned()` if type inference can't help.
parent 6d3eccb3
No related branches found
No related tags found
1 merge request!36refactoring: uniform string conversion
Pipeline #3498 passed
......@@ -69,7 +69,7 @@ mod test {
drop(_savepoint);
assert_ne!(
std::env::var("PATH").ok(),
Some("ensure:savepoint:works".to_owned())
Some("ensure:savepoint:works".into())
);
Ok(())
......
......@@ -63,13 +63,13 @@ fn main_run(matches: &clap::ArgMatches) {
if let Some(peer) = matches.values_of("peer") {
let append = |s: String, str| if s.is_empty() { s + str } else { s + "," + str };
let peer = peer.fold(String::new(), append);
envp.insert("PICODATA_PEER".to_owned(), peer);
envp.insert("PICODATA_PEER".into(), peer);
}
envp.entry("PICODATA_LISTEN".to_owned())
.or_insert_with(|| "3301".to_owned());
envp.entry("PICODATA_DATA_DIR".to_owned())
.or_insert_with(|| ".".to_owned());
envp.entry("PICODATA_LISTEN".into())
.or_insert_with(|| "3301".into());
envp.entry("PICODATA_DATA_DIR".into())
.or_insert_with(|| ".".into());
let bypass_vars = [
"cluster-id",
......@@ -82,7 +82,7 @@ fn main_run(matches: &clap::ArgMatches) {
for var in bypass_vars {
if let Some(v) = matches.value_of(var) {
let k = format!("PICODATA_{}", var.to_uppercase().replace("-", "_"));
envp.insert(k, v.to_owned());
envp.insert(k, v.into());
}
}
......@@ -102,7 +102,7 @@ fn main_run(matches: &clap::ArgMatches) {
p.into_os_string().into_string().unwrap()
};
envp.entry("LUA_CPATH".to_owned())
envp.entry("LUA_CPATH".into())
.and_modify(|v| *v = format!("{};{}", cpath, v))
.or_insert(cpath);
......
......@@ -55,12 +55,12 @@ inventory::submit!(crate::InnerTest {
assert_eq!(ser((Message::Empty,)), json!([["empty"]]));
let msg = Message::Info {
msg: "hello, serde!".to_owned(),
msg: "hello, serde!".into(),
};
assert_eq!(ser((msg,)), json!([["info", "hello, serde!"]]));
let msg = Message::EvalLua {
code: "return true".to_owned(),
code: "return true".into(),
};
assert_eq!(ser((msg,)), json!([["eval_lua", "return true"]]));
......@@ -72,13 +72,11 @@ inventory::submit!(crate::InnerTest {
let buf: Vec<u8> = rmp_serde::to_vec(&("info", "xxx")).unwrap();
assert_eq!(
Message::try_from(buf.as_ref()).unwrap(),
Message::Info {
msg: "xxx".to_owned()
}
Message::Info { msg: "xxx".into() }
);
let msg = Message::EvalLua {
code: "os.exit()".to_owned(),
code: "os.exit()".into(),
};
let buf: Vec<u8> = Vec::from(&msg);
assert_eq!(
......@@ -93,7 +91,7 @@ inventory::submit!(crate::InnerTest {
let buf = [0xCCu8]; // truncated u8
assert_eq!(
Message::try_from(&buf as &[u8]).map_err(|e| format!("{e}")),
Err("IO error while reading data: failed to fill whole buffer".to_owned())
Err("IO error while reading data: failed to fill whole buffer".into())
);
}
});
......@@ -45,9 +45,9 @@ pub struct Cfg {
impl Default for Cfg {
fn default() -> Self {
Self {
listen: Some("3301".to_owned()),
wal_dir: ".".to_owned(),
memtx_dir: ".".to_owned(),
listen: Some("3301".into()),
wal_dir: ".".into(),
memtx_dir: ".".into(),
feedback_enabled: false,
}
}
......
......@@ -89,30 +89,26 @@ inventory::submit!(crate::InnerTest {
);
assert_eq!(
ser(Entry::new(Message::Info {
msg: "!".to_owned()
})),
ser(Entry::new(Message::Info { msg: "!".into() })),
json!(["EntryNormal", 0u64, 0u64, ["info", "!"]])
);
assert_eq!(
ser(Entry {
entry_type: "EntryNormal".to_owned(),
entry_type: "EntryNormal".into(),
index: 1001,
term: 1002,
msg: Message::EvalLua {
code: "return nil".to_owned(),
code: "return nil".into(),
},
}),
json!(["EntryNormal", 1001u64, 1002u64, ["eval_lua", "return nil"]])
);
let msg = Message::Info {
msg: "?".to_owned(),
};
let msg = Message::Info { msg: "?".into() };
assert_eq!(
raft::Entry::try_from(self::Entry {
entry_type: "EntryConfChangeV2".to_owned(),
entry_type: "EntryConfChangeV2".into(),
index: 99,
term: 2,
msg: msg.clone(),
......@@ -131,12 +127,12 @@ inventory::submit!(crate::InnerTest {
///////////////////////////////////////////////////////////////////////
let row = self::Entry {
entry_type: "EntryUnknown".to_owned(),
entry_type: "EntryUnknown".into(),
..Default::default()
};
assert_eq!(
raft::Entry::try_from(row).map_err(|e| format!("{e}")),
Err("unknown entry type \"EntryUnknown\"".to_owned())
Err("unknown entry type \"EntryUnknown\"".into())
);
assert_eq!(
......
......@@ -143,23 +143,23 @@ inventory::submit!(crate::InnerTest {
assert_eq!(
raft::Message::try_from(Message {
msg_type: "MsgUnknown".to_owned(),
msg_type: "MsgUnknown".into(),
..Default::default()
})
.map_err(|e| format!("{e}")),
Err("unknown message type \"MsgUnknown\"".to_owned())
Err("unknown message type \"MsgUnknown\"".into())
);
assert_eq!(
raft::Message::try_from(Message {
entries: vec![row::Entry {
entry_type: "EntryUnknown".to_owned(),
entry_type: "EntryUnknown".into(),
..Default::default()
}],
..Default::default()
})
.map_err(|e| format!("{e}")),
Err("unknown entry type \"EntryUnknown\"".to_owned())
Err("unknown entry type \"EntryUnknown\"".into())
);
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment