Skip to content

Commit

Permalink
outfeed: use smartstring crate.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
miquels committed Jul 9, 2020
1 parent 0608c13 commit e270fd7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ toml = "0.5.6"
trust-dns-resolver = "0.19.5"
users = "0.10.0"
smallvec = "1.4.0"
smartstring = "0.2.3"
lock_api = "0.4.0"

[dev-dependencies]
Expand Down
14 changes: 7 additions & 7 deletions src/dconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,13 @@ fn set_newspeer_item(peer: &mut NewsPeer, words: &[&str]) -> io::Result<()> {

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

//"groups" => parse_num_list(&mut peer.groups.patterns, words, ",")?,
"addgroup" => peer.groups.push(parse_group(words)?),
"delgroup" => peer.groups.push("!".to_string() + &parse_group(words)?),
"delgroupany" => peer.groups.push("@".to_string() + &parse_group(words)?),
"groupref" => peer.groups.push("=".to_string() + &parse_group(words)?),
"delgroup" => peer.groups.push("!".to_string() + parse_group(words)?.as_str()),
"delgroupany" => peer.groups.push("@".to_string() + parse_group(words)?.as_str()),
"groupref" => peer.groups.push("=".to_string() + parse_group(words)?.as_str()),

"outhost" => peer.outhost = parse_string(words)?,
"hostname" => peer.outhost = parse_string(words)?,
Expand Down Expand Up @@ -450,9 +450,9 @@ fn set_groupdef_item(gdef: &mut GroupDef, words: &[&str]) -> io::Result<()> {
match words[0] {
// "groups" => parse_list(&mut gdef.groups, words, ",")?,
"addgroup" => gdef.groups.push(parse_string(words)?),
"delgroup" => gdef.groups.push("!".to_string() + &parse_string(words)?),
"delgroupany" => gdef.groups.push("@".to_string() + &parse_string(words)?),
"groupref" => gdef.groups.push("=".to_string() + &parse_string(words)?),
"delgroup" => gdef.groups.push("!".to_string() + parse_string(words)?.as_str()),
"delgroupany" => gdef.groups.push("@".to_string() + parse_string(words)?.as_str()),
"groupref" => gdef.groups.push("=".to_string() + parse_string(words)?.as_str()),
_ => Err(invalid_data!("{}: unrecognized keyword", words[0]))?,
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,10 @@ fn handle_panic() {
let mut msg = "".to_string();
let mut loc = "".to_string();
if let Some(s) = info.payload().downcast_ref::<&str>() {
msg = "'".to_string() + s + "', ";
msg = "'".to_string() + *s + "', ";
}
if let Some(s) = info.payload().downcast_ref::<String>() {
msg = "'".to_string() + &s + "', ";
msg = "'".to_string() + s.as_str() + "', ";
}
if let Some(l) = info.location() {
loc = format!("{}", l);
Expand Down
11 changes: 6 additions & 5 deletions src/outfeed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::Arc;

use futures::sink::{Sink, SinkExt};
use parking_lot::Mutex;
use smartstring::alias::String as SmartString;
use tokio::net::TcpStream;
use tokio::prelude::*;
use tokio::stream::StreamExt;
Expand All @@ -28,7 +29,7 @@ pub struct FeedArticle {
// Location in the article spool.
location: ArtLoc,
// Peers to feed it to.
peers: Vec<String>,
peers: Vec<SmartString>,
}

// Sent from masterfeed -> peerfeed -> connection.
Expand Down Expand Up @@ -59,7 +60,7 @@ pub struct MasterFeed {
art_chan: mpsc::Receiver<FeedArticle>,
bus: bus::Receiver,
newsfeeds: Arc<NewsFeeds>,
peerfeeds: HashMap<String, mpsc::Sender<PeerFeedItem>>,
peerfeeds: HashMap<SmartString, mpsc::Sender<PeerFeedItem>>,
spool: Spool,
}

Expand All @@ -84,20 +85,20 @@ impl MasterFeed {

// Find out what peers from self.peerfeeds are not in the new
// newsfeed, and remove them.
let mut removed: HashSet<_> = self.peerfeeds.keys().cloned().collect();
let mut removed: HashSet<_> = self.peerfeeds.keys().map(|s| s.as_str().to_owned()).collect();
for peer in &self.newsfeeds.peers {
removed.remove(&peer.label);
}
for peer in removed.iter() {
self.peerfeeds.remove(peer);
self.peerfeeds.remove(peer.as_str());
}

// Now add new peers.
for peer in &self.newsfeeds.peers {
let peer_feed = PeerFeed::new(peer, &self.newsfeeds, &self.spool);
let tx_chan = peer_feed.tx_chan.clone();
tokio::spawn(async move { peer_feed.run().await });
self.peerfeeds.insert(peer.label.clone(), tx_chan);
self.peerfeeds.insert(peer.label.clone().into(), tx_chan);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/spool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Debug for ArtLoc {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let token = &self.token[..self.toklen as usize]
.iter()
.fold("0x".to_string(), |acc, x| acc + &format!("{:02x}", x));
.fold("0x".to_string(), |acc, x| acc + format!("{:02x}", x).as_str());
f.debug_struct("ArtLoc")
.field("storage_type", &self.storage_type.name())
.field("spool", &self.spool)
Expand Down

0 comments on commit e270fd7

Please sign in to comment.