Browse Source

Add support for latest Rust features via `--features latest_rust`

atomic-counter
Roman Zeyde 5 years ago
parent
commit
bebbfa197d
No known key found for this signature in database GPG Key ID: 87CAE5FA46917CBB
  1. 3
      Cargo.toml
  2. 30
      src/daemon.rs

3
Cargo.toml

@ -11,6 +11,9 @@ documentation = "https://docs.rs/electrs/"
readme = "README.md"
edition = "2018"
[features]
latest_rust = [] # use latest Rust features (otherwise, support Rust 1.32)
[dependencies]
arrayref = "0.3"
base64 = "0.10"

30
src/daemon.rs

@ -13,7 +13,9 @@ use std::collections::{HashMap, HashSet};
use std::io::{BufRead, BufReader, Lines, Write};
use std::net::{SocketAddr, TcpStream};
use std::path::PathBuf;
use std::sync::{Arc, Mutex, atomic::{AtomicU64, Ordering}};
#[cfg(feature = "latest_rust")]
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex};
use std::time::Duration;
use crate::errors::*;
@ -266,15 +268,15 @@ impl Connection {
}
}
#[cfg(feature = "latest_rust")]
struct Counter {
value: AtomicU64,
}
#[cfg(feature = "latest_rust")]
impl Counter {
fn new() -> Self {
Counter {
value: 0.into(),
}
Counter { value: 0.into() }
}
fn next(&self) -> u64 {
@ -283,6 +285,26 @@ impl Counter {
}
}
#[cfg(not(feature = "latest_rust"))]
struct Counter {
value: Mutex<u64>,
}
#[cfg(not(feature = "latest_rust"))]
impl Counter {
fn new() -> Self {
Counter {
value: Mutex::new(0),
}
}
fn next(&self) -> u64 {
let mut value = self.value.lock().unwrap();
*value += 1;
*value
}
}
pub struct Daemon {
daemon_dir: PathBuf,
network: Network,

Loading…
Cancel
Save