Skip to content

Commit e270fd7

Browse files
committed
outfeed: use smartstring crate.
Note that right now `smartstring` influences String/&string references to deref to &str. So "String + &String" fails, while "String + (&String).as_str()" works. See bodil/smartstring#7
1 parent 0608c13 commit e270fd7

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ toml = "0.5.6"
5858
trust-dns-resolver = "0.19.5"
5959
users = "0.10.0"
6060
smallvec = "1.4.0"
61+
smartstring = "0.2.3"
6162
lock_api = "0.4.0"
6263

6364
[dev-dependencies]

src/dconfig.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ fn set_newspeer_item(peer: &mut NewsPeer, words: &[&str]) -> io::Result<()> {
380380

381381
"distributions" => parse_list(&mut peer.distributions, words, ",")?,
382382
"adddist" => peer.distributions.push(parse_string(words)?),
383-
"deldist" => peer.distributions.push("!".to_string() + &parse_string(words)?),
383+
"deldist" => peer.distributions.push("!".to_string() + parse_string(words)?.as_str()),
384384

385385
//"groups" => parse_num_list(&mut peer.groups.patterns, words, ",")?,
386386
"addgroup" => peer.groups.push(parse_group(words)?),
387-
"delgroup" => peer.groups.push("!".to_string() + &parse_group(words)?),
388-
"delgroupany" => peer.groups.push("@".to_string() + &parse_group(words)?),
389-
"groupref" => peer.groups.push("=".to_string() + &parse_group(words)?),
387+
"delgroup" => peer.groups.push("!".to_string() + parse_group(words)?.as_str()),
388+
"delgroupany" => peer.groups.push("@".to_string() + parse_group(words)?.as_str()),
389+
"groupref" => peer.groups.push("=".to_string() + parse_group(words)?.as_str()),
390390

391391
"outhost" => peer.outhost = parse_string(words)?,
392392
"hostname" => peer.outhost = parse_string(words)?,
@@ -450,9 +450,9 @@ fn set_groupdef_item(gdef: &mut GroupDef, words: &[&str]) -> io::Result<()> {
450450
match words[0] {
451451
// "groups" => parse_list(&mut gdef.groups, words, ",")?,
452452
"addgroup" => gdef.groups.push(parse_string(words)?),
453-
"delgroup" => gdef.groups.push("!".to_string() + &parse_string(words)?),
454-
"delgroupany" => gdef.groups.push("@".to_string() + &parse_string(words)?),
455-
"groupref" => gdef.groups.push("=".to_string() + &parse_string(words)?),
453+
"delgroup" => gdef.groups.push("!".to_string() + parse_string(words)?.as_str()),
454+
"delgroupany" => gdef.groups.push("@".to_string() + parse_string(words)?.as_str()),
455+
"groupref" => gdef.groups.push("=".to_string() + parse_string(words)?.as_str()),
456456
_ => Err(invalid_data!("{}: unrecognized keyword", words[0]))?,
457457
}
458458
Ok(())

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,10 @@ fn handle_panic() {
392392
let mut msg = "".to_string();
393393
let mut loc = "".to_string();
394394
if let Some(s) = info.payload().downcast_ref::<&str>() {
395-
msg = "'".to_string() + s + "', ";
395+
msg = "'".to_string() + *s + "', ";
396396
}
397397
if let Some(s) = info.payload().downcast_ref::<String>() {
398-
msg = "'".to_string() + &s + "', ";
398+
msg = "'".to_string() + s.as_str() + "', ";
399399
}
400400
if let Some(l) = info.location() {
401401
loc = format!("{}", l);

src/outfeed.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::sync::Arc;
77

88
use futures::sink::{Sink, SinkExt};
99
use parking_lot::Mutex;
10+
use smartstring::alias::String as SmartString;
1011
use tokio::net::TcpStream;
1112
use tokio::prelude::*;
1213
use tokio::stream::StreamExt;
@@ -28,7 +29,7 @@ pub struct FeedArticle {
2829
// Location in the article spool.
2930
location: ArtLoc,
3031
// Peers to feed it to.
31-
peers: Vec<String>,
32+
peers: Vec<SmartString>,
3233
}
3334

3435
// Sent from masterfeed -> peerfeed -> connection.
@@ -59,7 +60,7 @@ pub struct MasterFeed {
5960
art_chan: mpsc::Receiver<FeedArticle>,
6061
bus: bus::Receiver,
6162
newsfeeds: Arc<NewsFeeds>,
62-
peerfeeds: HashMap<String, mpsc::Sender<PeerFeedItem>>,
63+
peerfeeds: HashMap<SmartString, mpsc::Sender<PeerFeedItem>>,
6364
spool: Spool,
6465
}
6566

@@ -84,20 +85,20 @@ impl MasterFeed {
8485

8586
// Find out what peers from self.peerfeeds are not in the new
8687
// newsfeed, and remove them.
87-
let mut removed: HashSet<_> = self.peerfeeds.keys().cloned().collect();
88+
let mut removed: HashSet<_> = self.peerfeeds.keys().map(|s| s.as_str().to_owned()).collect();
8889
for peer in &self.newsfeeds.peers {
8990
removed.remove(&peer.label);
9091
}
9192
for peer in removed.iter() {
92-
self.peerfeeds.remove(peer);
93+
self.peerfeeds.remove(peer.as_str());
9394
}
9495

9596
// Now add new peers.
9697
for peer in &self.newsfeeds.peers {
9798
let peer_feed = PeerFeed::new(peer, &self.newsfeeds, &self.spool);
9899
let tx_chan = peer_feed.tx_chan.clone();
99100
tokio::spawn(async move { peer_feed.run().await });
100-
self.peerfeeds.insert(peer.label.clone(), tx_chan);
101+
self.peerfeeds.insert(peer.label.clone().into(), tx_chan);
101102
}
102103
}
103104

src/spool/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Debug for ArtLoc {
112112
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
113113
let token = &self.token[..self.toklen as usize]
114114
.iter()
115-
.fold("0x".to_string(), |acc, x| acc + &format!("{:02x}", x));
115+
.fold("0x".to_string(), |acc, x| acc + format!("{:02x}", x).as_str());
116116
f.debug_struct("ArtLoc")
117117
.field("storage_type", &self.storage_type.name())
118118
.field("spool", &self.spool)

0 commit comments

Comments
 (0)